我有一个函数作为一个教程游戏的一部分。如果满足某个条件(如果对象==“code”),则该函数应触发另一个函数
# right room
def right_room():
print "You see a table with two objects: a map and a code translator"
print "You can take one object"
print "Which object do you take?"
next = raw_input("> ")
if "map" in next and "code" in next:
dead("You're greed surpassed your wisdom.")
elif "map" in next:
print "OK, you have the map."
theobject = "map"
print "Now you must exit and go ahead"
return theobject
opening()
elif "code" in next:
print "OK, you have the code."
theobject = "code"
print "Now you must exit and go ahead."
return theobject
opening()
但开放不叫开放吗?以下是输出:
You're in a Labrynthe. There's a door on your left. There's a door on your right. Or you can go ahead.
right You see a table with two objects: a map and a code translator You can take one object Which object do you take? code OK, you have the code. Now you must exit and go ahead.
然后,上面的功能意味着将人员发送回起始位置,并提示他们在终端中输入“ahead”:
# opening scene
def opening():
print "You're in a Labrynthe."
print "There's a door on your left."
print "There's a door on your right."
print "Or you can go ahead."
next = raw_input("> ")
if "right" in next:
right_room()
elif "left" in next:
left_room()
elif "ahead" in next:
ahead()
else:
print "Which way will you go?"
但不调用opening()。相反,Python似乎完成了脚本并退出了。你知道吗
Python中的
return
语句(几乎所有语言都是Haskell的显著例外)意味着函数应该在那里停止。如果语句是return expr
,则表达式的值可供调用方使用。否则,在Python中,调用者可以使用值None
。你知道吗因此,您可能需要在
return
语句之前移动函数调用。你知道吗相关问题 更多 >
编程相关推荐