我做了一个简单的游戏,询问用户是否想通过输入Y / N来继续。 但是如果用户输入的内容不是那样的话,我想问这个问题。我该怎么做?
def start():
print "Hello there."; time.sleep(.5)
myname = raw_input("What is your name? "); time.sleep(.5)
print "Welcome %s, this is..." %myname; time.sleep(.5)
uname = myname.upper()
print "\t\t\tTHE ADVENTURES OF %s" %uname
choice0 = raw_input("\nWould you like to play the game? Y/N ")
if choice0 == "Y":
gameon
if choice0 == "N":
print "Alright, bye!"
else:
print "Invalid input."
答案 0 :(得分:2)
choice0 = ''
allowed = ["y", "n"]
while choice0.lower() not in allowed:
choice0 = raw_input("\nWould you like to play the game? Y/N ")