lundi 10 juillet 2017

Python If statement and logical operator issue [duplicate]

This question already has an answer here:

I'm trying to create a small python program to emulate rolling a single die. My problem arises in that I want the program to accept both upper and lower-case 'Y' to trigger a re-roll. My program works when I accept either upper or lower case y but when I try to change the line

if usr == 'Y'

to

if usr == 'Y' or 'y'

creates a problem where it never enters the else statement, making the program never terminate.

import random

def DiceRoll():
 number = random.randrange(1, 7, 1)
 print("Dice Roll: ", number)
 AskUser()
 return

def AskUser():
 usr = input("Roll Again? (Y/N) \n")
 if usr == 'Y':
     DiceRoll()
 else :
     print("Thank you for playing!")
return

DiceRoll()

Aucun commentaire:

Enregistrer un commentaire