I'm programming a yahtzee like game where a player rolls 5 dice and gets to pick which dice to re-roll.
I can't get my function to properly iterate over the user input verify that they are valid.
Here's some code:
def diceroll():
raw_input("Press enter to roll dice: ")
a = random.randint(1, 6)
b = random.randint(1, 6)
c = random.randint(1, 6)
d = random.randint(1, 6)
e = random.randint(1, 6)
myroll.append(a)
myroll.append(b)
myroll.append(c)
myroll.append(d)
myroll.append(e)
print "Your roll:"
print myroll
diceSelect()
def diceSelect():
s = raw_input("Enter the numbers of the dice you'd like to roll again, separated by spaces, then press ENTER: ")
rollAgain = map(int, s.split())
updateMyRoll(rollAgain)
def updateMyRoll(a):
reroll = []
for n in a:
if n in myroll:
reroll.append(n)
removeCommonElements(myroll, a)
print "deleting elements..."
elif n not in myroll:
print "I don't think you rolled", n, "."
diceSelect()
else:
print "I don't understand..."
diceSelect()
print "Your remaining dice: ", myroll
def removeCommonElements(a,b,):
for e in a[:]:
if e in b:
a.remove(e)
b.remove(e)
The problem is likely in the diceSelect function, such that I can enter only true values and it works fine, I can enter only false values and get the desired effect for ONLY the first false value (which I understand based on the code... but would like to change), or I can enter true AND false values but it ONLY acts on the true values but ignores the false values.
How can I iterate over these values and re-prompt the user to enter all true values?