lundi 22 avril 2019

Python error: it gives me a number even if it should close [duplicate]

This question already has an answer here:

I'm a beginner in Python and I'm getting some trouble in a code, which should be something like a "dice simulator". when the program askes you if you want a dice roll, you can choose Y or N. When I chose N it gets me a number, even if it should exit the program

i've tried this:

while 1 == 1:
start = input("Do you want a dice roll? (Y/N) \n")
if start == "Y" or "y":
    number = random.randint(1,6)
    print(number)
else:
    sys.exit(0)

and this

while 1 == 1:
    start = input("Do you want a dice roll? (Y/N) \n")
if start != "n" or "N":
    number = random.randint(1,6)
    print(number)
else:
    sys.exit(0)




Aucun commentaire:

Enregistrer un commentaire