尝试使用另一个函数的raw_input

时间:2014-12-09 22:38:39

标签: python

来自sys import exit

def start():
    print "You woke up in a dungeon"
    print "There is three weapon in front of you"
    print "A sword, a staff and dagger"
    print "Which one do you choose"

choice = raw_input("")
if choice == "dagger":
    print "A rogue huh?"
elif choice == "staff":
    print "A wizard how interesting..."
elif choice == "sword":
    print "A warrior."
else:
    print "..."
dungeon_path()

def dungeon_path():
    if choice == "dagger":
        print "Which way you choose rogue"

start()

如果我在第一个功能中选择了匕首,我想要打印最后一行但是我似乎无法让它工作我试图给出一个值,然后使用"如果"但它也没那么奏效,所以我该做什么......

1 个答案:

答案 0 :(得分:1)

您可以将choice变量作为参数传递给dungeon_path函数:

...
        print "..."
    dungeon_path(choice)

def dungeon_path(choice):
    if choice == "dagger":
        print "Which way you choose rogue"