我试图在Learn Python the Hard Way exercise 35制作我自己的小游戏版本,并在提示用户在start()函数中首先进入他们要去的地方后,程序继续给出用户来自candyKingdom()函数中start()的提示。这里发生了什么?
这是我的代码:
from sys import exit
def start():
print "Welcome to Ooo! Many mathematical adventures await thee, saucy warrior!"
global warrior
warrior = raw_input("Why don't you tell us your name first? ")
print "Why hello there, " + warrior + "!"
print "Where would you like to go, " + warrior + "? \n You can type: Candy Kingdom, Ice Kingdom, Fire Kingdom, \n Treehouse, or Nightosphere"
while True: ## This allows the user to try again if they don't type the names in just right.
choice = raw_input("Choose wisely, " + warrior + "!: ")
if choice == "Candy Kingdom":
candyKingdom()
elif choice == "Ice Kingdom":
iceKingdom()
elif choice == "Fire Kingdom":
fireKingdom()
elif choice == "Treehouse":
treehouse()
elif choice == "Nightosphere":
nightosphere()
elif choice == "exit":
exit(0)
else:
print "That's not a choice! Try again!"
def candyKingdom():
print "Thank you for coming to our rescue, " + warrior + "! We've got a major problem here!"
print "Starchy's locked himself in the closet and he won't come out!"
choice = raw_input("Can you help us? Yes or no? ")
在这里,我至少期望程序在崩溃之前给我提示candyKingdom()或者其他什么,但是我再次从上一个函数得到提示:
Where would you like to go, Finn?
You can type: Candy Kingdom, Ice Kingdom, Fire Kingdom,
Treehouse, or Nightosphere
Choose wisely, Finn!: Candy Kingdom
Welcome to the Candy Kingdom, Finn! We've got a major problem here!
Starchy's locked himself in the closet and he says he won't come out! Can you help us?
Choose wisely, Finn!:
任何人都知道这里发生了什么?