我在用冒险时间做一个文本游戏。但是,一个值似乎没有保存。我使用的是64位windows7,使用的是python3.4.1
我得到的错误是
名称错误:未定义名称“character”
请帮我解决我的问题。提前谢谢。
def characterask ():
character = input ('''What character from the show should you be? (Finn or Jake)
If you are unfamiliar with the show, Finn is a human boy specialized in melee combat and Jake is a dog with the ability to stretch into anything.''')
try:
if character == "Finn" or character == "Jake":
print("Your character is ", character)
else:
print("That character's name is not Finn or Jake.")
print
characterask ()
except ValueError:
print ("That character's name is not Finn or Jake.")
print
characterask ()
print
characterask ()
time = input("What time is it?")
如果(时间==“冒险时间”): 打印(“我们走!”) 其他: 打印(“不,”,姓名) 打印(“冒险时刻!!!”) 打印(“我们走!”)你知道吗
你去糖果王国。冰王冻结了一切,并试图绑架布布勒格姆公主。他带着神奇的胡须飞行。”) 定义选项1(): 打印(“你会怎么做?!”) 如果字符==“Finn”: answerq1c1=输入(''''a.让杰克把你拉大,这样你就可以打他的脸了!!!!! b、 走进布布勒格姆公主的塔里,爬上星星。”“”) 尝试: 如果答案Q1C1==“a”: print(“你爬到杰克的背上。”) print(“杰克用他的魔法力量伸展他的腿,使之更长。”) print(“你从杰克背上跳到冰王面前,朝他脸上一拳。”) print(“你们现在都从危及生命的高度跌落。”) print(“杰克伸出双臂抓住你。”) print(“冰王在着陆前使用胡须异能恢复飞行。”) 冰王:我会抓到你的!“这还没结束!”) 打印(“冰王白痴地飞到墙上。”) 打印(“冰王:噢!”) 打印(“冰王:我来接你!”) 其他: 打印(“冰王注意到你和杰克试图进入塔楼。”) print(“他把你们俩都冻住了。”) 打印(“游戏结束”) 打印 开始() 除了值错误: 打印(“你的答案不是a或b”) 打印 选项1()
else:
answerq1c2 = input ('''a. Stretch Finn up so he can punch Ice King IN THE FACE!!!
b. Go inside Princess Bubblegum's tower and climb up the stars.''')
try:
if answerq1c2 == "a":
print("Finn climbes on your back.")
print("You stretch your legs to be longer using your magical powers.")
print("Finn jumps off of Your back towards Ice King and Finn punches him in the face.")
print("They are now both falling from a life threatening height.")
print("You stretch your arms and catch Finn.")
print("Ice King uses his beard powers to regain flight just before he hits the ground.")
print("Ice King: I'll get you! This isn't over!")
print("Ice King idiotically flies into a wall.")
print("Ice King: Ow!")
print("Ice King: I'll get you!")
else:
print("Ice King notices you and Jake trying to get in the tower.")
print("He freezes you both.")
print("GAME OVER")
print
start ()
except ValueError:
print ("Your answer was not a or b.")
print
choice1 ()
打印 选项1() 你知道吗
似乎在函数
choice1()
中,您在以下行中使用了character
变量:if character == "Finn":
。但是,这个变量是characterask()
函数中的局部变量。使字符全局化或在选项1中再次定义。你知道吗character
无法神奇地进入choice1
(换句话说,character
存在于characterask
的范围内,并且在其他范围内没有定义)。具体到第三行:要在
choice1
中访问它,您可以:characterask
)choice1
中以另一种方式请求,或者choice1
。你知道吗示例:
(以下是您可能的操作方法,简化为讨论中的代码)
character
是characterask
本地的。如果要在函数外部访问它,则需要返回值。你知道吗相关问题 更多 >
编程相关推荐