0

我正在做一个简单的游戏,询问用户是否想通过输入 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."
4

1 回答 1

2
choice0 = ''
allowed = ["y", "n"]
while choice0.lower() not in allowed:
    choice0 = raw_input("\nWould you like to play the game? Y/N ")
于 2012-09-26T02:08:53.953 回答