尝试使用另一个函数的原始输入

2024-05-13 02:31:29 发布

您现在位置:Python中文网/ 问答频道 /正文

从系统导入退出

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()

我想打印最后一行,如果我选择匕首在第一个功能,但我似乎无法得到它的工作我试图给选择一个值,然后用“如果”,但它也没有这样做,所以我该怎么办


Tags: inyouwhichifdefstartprintstaff
1条回答
网友
1楼 · 发布于 2024-05-13 02:31:29

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

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

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

相关问题 更多 >