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 に答える