【发布时间】:2018-12-15 06:31:18
【问题描述】:
我对编码很陌生,我正在制作一个冒险“游戏”来帮助我学习。玩家需要进行一些对话并做出决定,这会导致不同的选择,其中两个会询问他们的名字。我似乎无法让 player_name 变量出现在下一个函数中,它只是保持空白。我只是希望它作为一个全局变量,我可以在整个游戏中继续使用它。
player_name = ("")
def path_2():
print("I found you lying in the hallway.")
print("Maybe I should have left you there...")
player_name = input("What is your name? : ")
return player_name
def path_1():
print("It's a pleasure to meet you.")
print ("My name is Azazel. I am the warden of this place.")
print ("I found you lying in the hallway,")
print ("bleeding profusely from you head there.")
print ("")
player_name = input("What is your name? : ")
return player_name
def quest():
print(("This is a long story ")+str(player_name)+(" you'll have to be patient."))
enter()
【问题讨论】:
标签: python object variables global new-operator