Why is this python loop not working as I expect?
Question:
Why does it not generate two random numbers untill theyre are 5 and 3?
import random
rolla = int(0)
rollb = int(0)
while rolla != 5 and rollb != 3:
rolla = random.randint(1, 10)
rollb = random.randint(1, 11)
print(rolla, ' - ', rollb)
Answers:
import random
rolla = 0
rollb = 0
while not(rolla == 5 and rollb == 3):
rolla = random.randint(1, 10)
rollb = random.randint(1, 11)
print(rolla, ' - ', rollb)
you would have to use a not statement to encompass the entire phrase, otherwise it will stop if one of the conditions is false.
Change to:
while not (rolla == 5 and rollb == 3):
Why does it not generate two random numbers untill theyre are 5 and 3?
import random
rolla = int(0)
rollb = int(0)
while rolla != 5 and rollb != 3:
rolla = random.randint(1, 10)
rollb = random.randint(1, 11)
print(rolla, ' - ', rollb)
import random
rolla = 0
rollb = 0
while not(rolla == 5 and rollb == 3):
rolla = random.randint(1, 10)
rollb = random.randint(1, 11)
print(rolla, ' - ', rollb)
you would have to use a not statement to encompass the entire phrase, otherwise it will stop if one of the conditions is false.
Change to:
while not (rolla == 5 and rollb == 3):