If 文本冒险语句需要在继续之前检查元素列表

If statement for text adventure that requires checking a list for an element before continuing

我正在做的一项作业是 Python 基于文本的冒险游戏。它主要由可接受的选择列表和用于检查这些选择的 if 语句组成。一种选择需要检查名为 "inventory" 的列表中的元素。如果元素存在,则做一件事,否则做另一件事。语句的这个阶段不起作用,只是成立,但似乎所有的结构都是正确的。

def right_door():
    print('You push the door on the right open, revealing a long corridor.  "Now it gets interesting..."'
          'You hear a bleeping noise coming from your neck.  "Did you not notice the collar around your neck?  You '
          'may have guessed it already but that is a bomb.  It will blow in exactly three minutes.  Escape the '
          'building and it will disarm.  Otherwise... it\'s bye bye for' + playername + '!!  Oh and to make matters '
          'worse.  I have a friend who wants to meet you.  I would advise you don\'t give him that satisfaction"')
    print('\nYou see a man wielding a chainsaw standing at the door where you came from...')
    print('\n=========================================================================================================')
    print('Got to be quick on your feet here.  What do you do?')
    timer = threading.Timer(180, timer_fail_right_door)
    timer.start()
    choice = input('>> ')
    acceptable_choices = ['run', 'tamper', 'break', 'take of collar', 'escape', 'hide', 'pick up key', 'take key',
                          'key', 'open chest', 'chest', 'open door', 'door', 'escape', 'fight', 'fight him', 'tackle',
                          'tackle']
    while choice.lower() not in acceptable_choices:
        print('I don\'t quite understand that command')

    if choice.lower() in ['run', 'escape']:
        print('You make a break for it, sprinting down the corridor.  You hear heavy footsteps and panting behind you,'
              'driving you to run as quick as your legs will take you.  You come to a large room.  Looks like an old '
              'warehouse or storage facility.  You quickly enter and slam the door behind you!  You see a door '
              'straight in front of you, and there are plenty of places to hide.')
        print('\n=====================================================================================================')
        print('What do you do?')
        choice = input('>> ')
        if choice.lower() in ['hide']:
            print('You duck behind some storage boxes, hoping the person doesnt see you.  They search frantically '
                  'screaming your name.  Whilst you are hiding you spot a key by your feet.')
            print('\n=================================================================================================')
            print('What do you do?')
            choice = input('>> ')
            if choice.lower() in ['pick up key', 'key', 'take key']:
                inventory.append('key')
                print('You take the key.  Perhaps it is for the door ahead of you.  Then again it could also be for '
                      'the treasure chest on the opposite side of the room.')
                print(
                    '\n===============================================================================================')
                print('What do you do?')
                choice = input('>> ')
                if choice.lower() in ['open chest', 'chest']:
                    print('You open the chest.  Your eyes widen as you discover it is full of GOLD!! What you don\'t '
                          'realise is that it is of no use to you here.  You look up and see the bomb straddling mad '
                          'man above you...')
                    print('\nYou have died...')
                    game_over()
                elif choice.lower in ['open door', 'door']:
                    if 'key' in inventory:
                        print('You open the door and step through.  YOU ARE BACK IN YOUR BEDROOM!!  You do not know how'
                              ' you got here or what happened.  You\'re just happy you are home.')
                        game_complete()
                    elif 'key' not in inventory:
                        print('You try and open the door, but it is locked.  You turn round only to be greeted by a '
                              'chainsaw.  You meet a gruesome death.')
                        print('\nYou have dies...')
                        game_over()

您在以下行中缺少括号:

                elif choice.lower in ['open door', 'door']:

这不会return任何东西。它不会进入状态。

并且,我希望您知道在检查列表中的内容时,该命令应该与列表元素完全匹配。

Str.lower是字符串的方法,所以需要调用函数。请改用 variable.lower()