我写了这个作为一个例子:函数错误中的Python函数?
def function():
choice = raw_input("> ")
if choice == "attack":
print "Killed the monster."
elif choice == "run":
print "You run but the monster follows you. Activate jetpack? (y/n)"
def function_in_function():
choice = raw_input("> ")
if choice == "y":
print "You fly to safety."
elif choice == "n":
print "You get stomped."
else:
print "That's not an option."
function_in_function()
else:
print "That's not an option."
function()
我打开了它的电源外壳,但一无所获?
顶行下方的所有内容至少需要缩进4个空格。 – Andrew
缩进是错误的。 –
如果这被保存为一个.py文件,并且你执行该文件,则不会发生任何事情,因为你所做的只是定义一个函数,但从不执行它。 – syntonym