[Python] elif iterating more than expected

Discussão em 'Python' iniciado por Stack, Julho 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm making an text based game but even if the player inputs a valid direction both 'true' and 'false' statements print, how can I stop this?


    # A dictionary for the simplified dragon text game
    # The dictionary links a room to other rooms.
    rooms = {
    'Great Hall': {'South': 'Bedroom'},
    'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
    'Cellar': {'West': 'Bedroom'}
    }

    exit_game = False
    current_area = 'Great Hall'
    movement = ['North', 'East', 'South', 'West', 'Exit']
    direction = '' # player direction will be defined by player input
    print('Movement: North, East, South, West, or Exit.')
    print('-' * 50)
    while direction != 'exit' and direction != 'Exit':
    # prints available direction
    # print(*rooms[current_area].keys())
    # prints available room
    # print(*rooms[current_area].values())
    # prints both
    # print('To your ', *rooms[current_area].keys(),' is the ', *rooms[current_area].values(), '.', sep='')
    # ---------------------------------------------
    print('Your are in the: ', current_area, '.', sep='')
    print('To your ', *rooms[current_area].keys(), ' is the ', *rooms[current_area].values(), '.', sep='')
    direction = input('Which way do you want to move?')
    print('You entered:', direction)
    direction = direction.capitalize()
    for value in rooms.values():
    if direction in value:
    print('True')
    elif direction not in value:
    print('false')
    break
    print('-' * 50)



    I tried capitalizing the users input before the for loop but i'm stuck...

    Continue reading...

Compartilhe esta Página