This is a very simple dice roll program that keeps rolling two dice until it gets double sixes. So my while statement is structured as:
while DieOne != 6 and DieTwo != 6:
For some reason, the program ends as soon as DieOne
gets a six. DieTwo
is not considered at all.
But if I change the and
to an or
in the while statement, the program functions perfectly. This doesn't make sense to me.
import random
print('How many times before double 6s?')
num=0
DieOne = 0
DieTwo = 0
while DieOne != 6 or DieTwo != 6:
num = num + 1
DieOne = random.randint(1,6)
DieTwo = random.randint(1,6)
print(DieOne)
print(DieTwo)
print()
if (DieOne == 6) and (DieTwo == 6):
num = str(num)
print('You got double 6s in ' + num + ' tries!')
print()
break
DieOne
is 6 then the statementDieOne != 6 and DieTwo != 6
is false because it's not true the both die are not equal to six. – ConurbationNOT(die 1 is 6 AND die 2 is 6).
The equivalent condition becomesdie 1 is NOT 6 OR die 2 is NOT 6.
This is a logic problem that you'd need to work out. when you say "die 1 is not 6 AND die 2 is not 6", the condition will immediately fail the moment one of them become a 6, because AND needs to ensure BOTH conditions stay satisfied. – Oliywhile true
works just fine, you have a condition in place to leave the loop already. – Oliywhile DieOne+DieTwo != 12:
... or simplywhile True:
together with yourbreak
– Adorable