0 python
我可以用一些帮助搞清楚为什么我的游戏不允许我拿起一把剑.出现的错误消息是
回溯(最近一次调用最后一次):文件"",第36行,在文件"",第1行,在NameError中:名称'y'未定义
这是基本游戏,我对此非常新,所以简单的术语会很好.
print 'You enter a Dungeon with three doors. Do you want to enter door #1 door #2 or door #3?'
door = raw_input('> ')
if door == "1":
print 'Theres a dragon eating a human, the dragon is massive and looks terrifying'
print 'what do you want to do?'
print '#1 try to save the human'
print '#2 scream and run around'
dragon = raw_input('> ')
if dragon == "1":
print 'You approach the dragon sneakily. After what feel like a thousand years you are finally close to the dragon. You try to step closer. The dragon shifts and crushes you. Well done!'
elif dragon == "2":
print 'You scream and run around like a chicken with no head. The dragon is not impressed with you. It snorts and engulfs you in flames. You die a painful and worthless death. Well done!'
elif door == "2":
print 'You stare into a deep dark cave.'
print 'Oh dear, it seems you have been driven you quite insane.'
print '#1. drool'
print '#2. scream, drool, and walk forward'
print '#3. Understand computer programming completely and get an A plus'
insanity = raw_input('> ')
if insanity == "1":
print 'Your body survives but your mind does not, you drool for eternity!'
if insanity == "2":
print 'You slip on a mysterious liquid, then fall into a deep sleep, you awake years later at the kiss of a prince. Yay!'
if insanity == "3":
print 'Congradulations! You passed Programming! Time to graduate and face the real world.. So I guess you actully lost. Sorry.'
elif door == "3":
print ("You emerge into a brighter area and see a small sword lying on the ground")
ch1 = str(input("Do you take it? [y/n]:"))
if ch1 == "y":
print 'You have taken the sword!'
stick = 1
else:
print 'You have chosen not to take the sword'
sword = 0
Run Code Online (Sandbox Code Playgroud)
ch1 = str(input("Do you take it? [y/n]:"))
Run Code Online (Sandbox Code Playgroud)
如果您使用input并且用户键入"y",则解释器将搜索变量y并返回其值.你没有y变量,所以它崩溃了.你可能想在raw_input这里使用,而不是input.
ch1 = str(raw_input("Do you take it? [y/n]:"))
Run Code Online (Sandbox Code Playgroud)
顺便说一句,raw_input无论如何返回一个字符串,所以你真的不需要这个str电话.
ch1 = raw_input("Do you take it? [y/n]:")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
201 次 |
| 最近记录: |