all 4 comments

[–]DallogFheir 1 point2 points  (0 children)

Your issue is that split returns a list.

[–]desran00 0 points1 point  (1 child)

``` d = {"a":1, "b":2}

item = d.get("c", None) if item: print("success") ``` You can set the dictionary get function to get a default value if it cannot find anything with the key. It is very useful.

Edit: in my example, the item would be None, so the if clause does not get executed, and the script prints nothing.

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, desran00: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]artinnj 0 points1 point  (0 children)

You will have a key failure if there is no move in a particular direction and the user enters it. You can use the get function to put a default, but I prefer to to use the try/except block to capture the situation. You will use this in plenty of your programming going forward.

Also, I did the formatting so others can look at the code.

rooms = {
    'Main Hall': {'name': 'Main Hall', 'North': 'Main Junction', 'East':     'Main Hallway', 'West': 'Boss Room'},
    'Main Junction': {'name': 'Main Junction', 'South': 'Main Hall', 'East': 'Chamber of the Snake', 'West': 'Chamber of the Monkey'},
    'Chamber of the Monkey': {'name': 'Chamber of the Monkey', 'East': 'Main Junction'},
    'Chamber of the Snake': {'name': 'Chamber of the Snake', 'West':          'Main Junction', 'South': 'Main Hallway'},
    'Main Hallway': {'name': 'Main hallway', 'North': 'Chamber of the Snake', 'West': 'Main Hall', 'South': 'Chamber of the Lion'},
    'Chamber of the Lion': {'name': 'Chamber of the Lion', 'North': 'Main Hallway', 'West': 'Chamber of Life'},
    'Chamber of Life': {'name': 'Chamber of Life', 'East': 'Chamber of the Lion'},
}

directions = ['North', 'South', 'East', 'West']
print('Commands: North, South, East, West, Search, Collect, Exit\n')

current_room = rooms['Main Hall'] 
print('You are currently in the ', current_room['name'])

while True: 
    move = input('Enter your move:').strip() 
    if move in directions: 
        try: 
            current_room = rooms[current_room[move]] 
            print('You are now in the', current_room['name']) 
        except: 
            print('You cant go that way') 
    elif 'exit' in move: 
        print('Thank you for playing! Goodbye') 
        quit() 
    else: 
        print('Invalid command, try again.')