Reputation: 23
I am new to Python programming and i have a problem with the or statement in this program. When i run it in PyCharm and input 'roll' it works. But when i use 'yes' it seems not to do anything. while input() == ("roll") or input() == ("yes"): This line is the problem. I would like to know what I'm doing wrong here. When i use only one command for example roll it works perfectly for as many times as i want to run it.
# this is a dice rolling game
import random
min = 1
max = 6
def roll_dice():
x = random.randint(min, max)
print(x)
print("Would you like to roll the dice?")
while input() == ("roll") or input() == ("yes"):
roll_dice()
print("Would you like to roll the dice again ?")
Upvotes: 0
Views: 43
Reputation: 402813
Do not call input()
twice. Call it once and test for existence in a set using in
:
while input() in {'roll', 'yes'}:
...
If you're on python2, remember you'll need raw_input
, not input
.
Upvotes: 2