import random
lose = 'You Lose!'
point = 'You Got a Point!'
numPoints = 0
numloops = [0]
intro = 'Welcome to Point, Point, Lose! Get eight points and get the jackpot of up to $3.00!(25 cents per play)'
ad = 'Coming up next: rock paper scissors!'
print(intro)
print(ad)
cards = [point, point, point, lose]
for i in numloops:
random.shuffle(cards)
PChoice = input('Which card do you want to choose?(1, 2, 3 or 4): ')
if (PChoice == '1' and cards[0] == point):
numPoints += 1
if (PChoice == '2' and cards[1] == point):
numPoints += 1
if (PChoice == '3' and cards[2] == point):
numPoints += 1
if (PChoice == '4' and cards[3] == point):
numPoints += 1
if (PChoice == '1'):
print(cards[0])
if (PChoice == '2'):
print(cards[1])
if (PChoice == '3'):
print(cards[2])
if (PChoice == '4'):
print(cards[3])
if (PChoice != '1' and PChoice != '2' and PChoice != '3' and PChoice != '4'):
print('Please Input 1, 2, 3, 4.')
if (PChoice == '1' and cards[0] == lose):
break
if (PChoice == '2' and cards[1] == lose):
break
if (PChoice == '3' and cards[2] == lose):
break
if (PChoice == '4' and cards[3] == lose):
break
print(PChoice)
quit = input('Would you like to pick another card(yes/no): ')
if (quit == 'no' or quit == 'n'):
print('your score is,')
print(numPoints)
print('if you got one of the top ten high scores please show Avery.')
break
if (quit == 'yes' or quit == 'y'):
numloops.append(0)
if (quit != 'yes' and quit != 'no' and quit != 'y' and quit != 'n'):
print('Please type yes or no.')
if (numPoints >= 6):
cards.remove(point)
cards.append(lose)
Humans are pattern recognizing creatures, and so we also see patterns where no patterns exists; there are examples: here Apophenia - Wikipedia
The chances that you have found by eye some previously unnoticed regularity in Python’s heavily tested and reviewed random number generator is very very close to zero.
Which card do you want to choose?(1, 2, 3 or 4): 4
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 4
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 4
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 1
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 2
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 3
You Got a Point!
Would you like to pick another card(yes/no):
Which card do you want to choose?(1, 2, 3 or 4): 4
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 4
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 4
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 1
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 2
You Got a Point!
Would you like to pick another card(yes/no): y
Which card do you want to choose?(1, 2, 3 or 4): 3
You Got a Point!
Would you like to pick another card(yes/no):
To save some time we can remove all the game-playing bits and just test shuffle:
import random
cards = [True, True, True, False]
for i in [3, 3, 3, 0, 1, 2]:
random.shuffle(cards)
print(cards[i])
You’re saying this should just print True six times. It doesn’t on my machine. But how often does it?
import random
def test_shuffle():
all_true = True
cards = [True, True, True, False]
for i in [3, 3, 3, 0, 1, 2]:
random.shuffle(cards)
all_true &= cards[i]
return all_true
sum(test_shuffle() for i in range(10000))
I get somewhere around 1800 out of 10000, or 18%. This is what we’d expect from a random chance: we need to hit a 3/4 chance six time in a row, which 0.75 ** 6, around 0.177
If you can keep reproducing this exact pattern, I suspect you have a bug in your code, not in random.shuffle
It’s unlikely that this is a version issue–there has never been a pattern like this as far as I know. People would definitely notice!
The code you posted seems to differ a little bit from what you are actually running (there is a print statement in the example that isn’t in your output).
Maybe try copying the code in your post, above, and running it from scratch (several times). Then see if there’s any difference between that code and what you ran before.
Please make sure (by trying it yourself before posting) that someone else could copy and paste the code that you show us, without adding or changing anything, and see an exact result (by also copying and pasting from the example’s result) according to what you describe.
My guess is that in your “real” code, you have random.seed somewhere. It’s important to understand what this means, what it does, and how it works.
I have simplified the code a bit. Can you also replicate it with this one?
__doc__ = """
Welcome to Point, Point, Lose! Get eight points
and get the jackpot of up to $3.00!(25 cents per play)')
Coming up next: rock paper scissors!
"""
print(__doc__)
import random
lose = 'You Lose!'
point = 'You Got a Point!'
cards = [point, point, point, lose]
cards50 = [point, point, lose, lose]
IDX_MAP = {'1': 0, '2': 1, '3': 2, '4': 3, 'exit': 10}
total = 0
win = 0.25
while True:
random.shuffle(cards)
i = None
while i is None:
print('Please Input 1, 2, 3, 4. or "exit" to finish the game.')
PChoice = input('Which card do you want to choose?: ')
i = IDX_MAP.get(PChoice.strip('" '))
if i == 10:
break
card = cards[i]
print(card)
if card == point:
total += win
print('your current score is: ', total)
if total == 3:
break
elif total == 2:
cards = cards50
win = 0.5
else:
break
print('your score is: ', total)
print('if you got one of the top ten high scores please show Avery.')
still, must be something wrong with my computer I will check if I have outdated Windows.
Welcome to Point, Point, Lose! Get eight points
and get the jackpot of up to $3.00!(25 cents per play)')
Coming up next: rock paper scissors!
Please Input 1, 2, 3, 4. or “exit” to finish the game.
Which card do you want to choose?: 4
You Got a Point!
your current score is: 0.25
Please Input 1, 2, 3, 4. or “exit” to finish the game.
Which card do you want to choose?: 4
You Got a Point!
your current score is: 0.5
Please Input 1, 2, 3, 4. or “exit” to finish the game.
Which card do you want to choose?: 4
You Got a Point!
your current score is: 0.75
Please Input 1, 2, 3, 4. or “exit” to finish the game.
Which card do you want to choose?: 1
You Got a Point!
your current score is: 1.0
Please Input 1, 2, 3, 4. or “exit” to finish the game.
Which card do you want to choose?: 2
You Got a Point!
your current score is: 1.25
Please Input 1, 2, 3, 4. or “exit” to finish the game.
Which card do you want to choose?: 3
You Got a Point!
your current score is: 1.5
Please Input 1, 2, 3, 4. or “exit” to finish the game.
Which card do you want to choose?: exit
your score is: 1.5
if you got one of the top ten high scores please show Avery.