Jun-19-2019, 06:36 AM
I used this tutorial as a template. Why does mine get a KeyError and the tutorial doesn't? I even named the variables the same just to make sure I was right! I find this happens a lot. I try to copy something exactly and my version doesn't work. I can't find the difference!

rooms = {'numbers': {'o': 'one', 't': 'two'}} current_room = rooms['numbers'] directions = ['o', 't'] while True: for i in directions: print(i) command = input('Choose one. ').strip() if command in directions: if command in current_room: current_room = rooms[current_room[command]] else: print("You can't do that.") elif command.lower() in ('q', 'quit'): raise SystemExit else: print("I don't understand that command.")
Output:o
t
Choose one. o
Error:Traceback (most recent call last):
File "test.py", line 15, in <module>
current_room = rooms[current_room[command]]
KeyError: 'one'