Python 为什么我的指纹被跳过,而我得到了一个回溯错误?

Python 为什么我的指纹被跳过,而我得到了一个回溯错误?,python,python-3.x,Python,Python 3.x,我正在做Zed Shaw的《艰难地学习python 3》中练习36的家庭作业。我在写Zork式的文字冒险。这是真正的开始阶段。到目前为止,我已经测试了房间中的所有交互,除了一个,它们都可以工作 我想我在某个地方犯了语法错误,但我似乎找不到哪里,因为我是编程新手 def room1(): print('You have found a room with three doors: Left, Middle and Right') choice = input('Where

我正在做Zed Shaw的《艰难地学习python 3》中练习36的家庭作业。我在写Zork式的文字冒险。这是真正的开始阶段。到目前为止,我已经测试了房间中的所有交互,除了一个,它们都可以工作


我想我在某个地方犯了语法错误,但我似乎找不到哪里,因为我是编程新手



def room1():
    print('You have found a room with three doors: Left, Middle and  Right')

    choice = input('Where do you want to go?')
    if choice == 'left':
        room3()
    elif choice == 'right':
        room2()
    elif choice == 'middle':
        room5()
    else:
        print('You must pick one of the three')


def room2():
    print('You have found a room with three doors: Left, Middle and  Right')

    choice = input('Where do you want to go?')
    if choice == 'left':
        room1()
    elif choice == 'right':
        room4()
    elif choice == 'middle':
        room5()
    else:
        print('You must pick one of the three')

def room3():
    print('You enter an empty room, you might want to go back')

    choice = input('Do you wish to go back?')
    if choice == 'yes':
        print('You have returned to the previous room')
        room1()


def room4():
    print('You have found a room with a portal')

    choice = input('Take it?')
    if choice == 'yes':
        print('You went through it and now you are in another room')
        room6()
    elif choice == input():
        print('You are still in the same room')
    else:
        print('You must make a decision...')


def room5():
    print('You are now in a room with two doors: Left and right, pick one')

    choice = input('Left or right?')

    if choice == 'left':
        room6()
    if choice == 'right':
        room7()


def room6():
    print('You are in a room with a portal inside and a door.')

    choice = input('Choose portal or door')

    if choice == 'portal':
        room4()
    if choice == 'door':
        broom()


def room7():
    print('You are now in a room with two doors: Left and right, pick one')

    choice = input('Left or right?')

    if choice == 'left':
        room5()
    if choice == 'right':
        broom()


def broom():
    print('You enter a room and you trigger a trap')
    print('Pick your lucky number to see if you dodge the trap')

    choice = input('Lucky number')

    if choice > 100:
        print('GG')

    elif choice < 100:
        print('Death by trap')

    else:
        print('Pick a number!')


def start(): 
    # if start function is on top of code 
    # it wont work cuz it wont find room 1 and 2
    print('This is the start')
    print('You have two doors: Left and Right')

    choice = input ('Where do you want to go?')
    if choice == 'left':
        room1()
    elif choice == 'right':
        room2()
    else:
        dead('You must pick a door')


start()

def room1():
打印('您发现一个房间有三扇门:左、中、右')
choice=input('您想去哪里?')
如果选项==“左”:
房间3()
elif choice==“正确”:
房间2()
elif choice==“中间”:
房间5()
其他:
打印('必须从三个选项中选择一个')
def room2():
打印('您发现一个房间有三扇门:左、中、右')
choice=input('您想去哪里?')
如果选项==“左”:
房间1()
elif choice==“正确”:
房间4()
elif choice==“中间”:
房间5()
其他:
打印('必须从三个选项中选择一个')
def room3():
打印('您进入一个空房间,您可能想回去')
choice=input('您想返回吗?')
如果选项==“是”:
打印('您已返回上一个房间')
房间1()
def room4():
打印('您已找到带有入口的房间')
选择=输入(“接受它”)
如果选项==“是”:
打印('您已经完成了,现在您在另一个房间')
6号房间()
elif choice==input():
打印('您仍在同一个房间')
其他:
打印('您必须做出决定…')
def room5():
打印('您现在所在的房间有两扇门:左门和右门,选择一扇门')
选项=输入(“左”或“右”)
如果选项==“左”:
6号房间()
如果选项==‘正确’:
房间7()
def room6():
打印(“您所在的房间内有一个入口和一扇门。”)
选择=输入('选择入口或门')
如果选项==“门户”:
房间4()
如果选项==“门”:
扫帚
def room7():
打印('您现在所在的房间有两扇门:左门和右门,选择一扇门')
选项=输入(“左”或“右”)
如果选项==“左”:
房间5()
如果选项==‘正确’:
扫帚
def扫帚():
打印('您进入房间并触发陷阱')
打印('选择你的幸运号码,看看你是否躲过了陷阱')
选择=输入('幸运数字')
如果选择>100:
打印('GG')
elif选择<100:
打印(“陷阱死亡”)
其他:
打印('选择一个数字!')
def start():
#如果启动功能位于代码顶部
#它不起作用,因为它找不到1号和2号房间
打印('这是开始')
打印('您有两扇门:左门和右门')
choice=input('您想去哪里?')
如果选项==“左”:
房间1()
elif choice==“正确”:
房间2()
其他:
死('你必须选一扇门')
开始()
我希望选择一个数字和程序来检查它是否大于100,并采取相应的措施(打印)。然后在1号房间回来。 但我得到了一个错误:

Traceback (most recent call last):
  File "pex31.py", line 108, in <module>
    start()
  File "pex31.py", line 103, in start
    room2()
  File "pex31.py", line 24, in room2
    room4()
  File "pex31.py", line 44, in room4
    room6()
  File "pex31.py", line 68, in room6
    broom()
  File "pex31.py", line 86, in broom
    if choice > 100:
回溯(最近一次呼叫最后一次):
文件“pex31.py”,第108行,在
开始()
文件“pex31.py”,第103行,开头
房间2()
文件“pex31.py”,第24行,在room2中
房间4()
文件“pex31.py”,第44行,在room4中
6号房间()
文件“pex31.py”,第68行,第6房间
扫帚
文件“pex31.py”,第86行,在broom中
如果选择>100:
试试:

正如Kuro在评论中提到的那样:
选择
输入的类型是字符串,而在
if
语句中,您将其与整数进行比较,因此为了进行比较,您必须首先使用
int()
将字符串输入转换为整数


另外,您可能希望在
choice=int(输入('Lucky number'))
语句周围加一个
try:。。。除了:…
块来检查输入是否真的是整数,因为现在如果输入不能转换为整数,您的程序将崩溃。

选项
是字符串类型。你不能将它与整数值进行比较。“我想我在某个地方犯了语法错误,但我似乎找不到位置,因为我对编程不熟悉。”--你可以找到确切的位置,因为回溯包括行号和实际行数。经常阅读错误信息,你很快就会习惯的。请说明OP的代码有什么问题。因为他是一个初学者,粘贴代码对他没有帮助。谢谢你们试图帮助我。我想我会跳过这个“尝试和例外”的建议。这一点太先进了,哈哈。但我想我确实理解了我最初的错误。谢谢
choice = int(input('Lucky number'))