'Absolute beginner not sure what is wrong with this code involving random.randint
Typing 'no' is giving me the first two responses randomly (according to what choice the computer makes), which is what I want. But, for some reason currently unseen to me whenever I type 'yes' I only get the first 'yes' response (line 15).
Here's the program:
import random
var1 = 'Bro'
var2 = 'high'
compHigh = random.randint(0, 1)
compHigh = 'no' if compHigh == 0 else compHigh == 'yes'
while True:
answer = input('Hey %s, are you %s?: ' % (var1, var2))
if answer == 'no' and answer != compHigh:
print('Okay %s, you are not %s, but I am!' % (var1, var2))
break
if answer == 'no' and answer == compHigh:
print('Yo, %s. Neither of us are %s.' % (var1, var2))
break
if answer == 'yes' and answer != compHigh:
print('Congratulations %s, you are %s! I am not.' % (var1, var2))
break
if answer == 'yes' and answer == compHigh:
print('Ayyyyeee, %s! We are both %s!' % (var1, var2))
break
else:
continue
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
