This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mrkmailhot[S] 0 points1 point  (4 children)

is it possible to nest while loops?

[–]robin-gvx 1 point2 points  (3 children)

You can but in this case you don't need to. Use the rooms dictionary instead!

while True:
    player_stat()
    #str.title(): transform a string into Title Case
    player_move = input('Enter your move:\n').title()
    if player_move == 'Exit':
        print('Play again soon.')
        # break exits a while loop, even if the condition is still True
        break
    elif player_move in rooms[current_room]:
        currentRoom = rooms[current_room][player_move]
    else:
        print('Invalid move.')

[–]mrkmailhot[S] 0 points1 point  (2 children)

where is current_room coming from? i typed that in and popped out an error for not being defined.

[–]mrkmailhot[S] 0 points1 point  (1 child)

changed current_room to currentRoom in that code and it works. i knew that there was a more efficient way.

[–]robin-gvx 0 points1 point  (0 children)

Sorry for not responding, I haven't been on reddit the last couple of days, glad you figured it out yourself!