Question: Python help. Getting error on line 26. Correct the error. # dictionary of rooms and items rooms = { 'Hospital Room': {'East': 'Hall',

Python help. Getting error on line 26. Correct the error.

# dictionary of rooms and items

rooms = {

    'Hospital Room': {'East': 'Hall', 'item': 'None'},

    'Hall': {'East': 'Nurses Station', 'North': 'Physc Ward', 'South': 'ER', 'West': 'Hospital Room', 'item': 'Helmet'},

    'Nurses Station': {'West': 'Hall', 'item': 'Baton'},

    'Physc Ward': {'South': 'Hall', 'East': 'Critical Care', 'item': 'Tactical Shirt'},

    'Critical Care': {'West': 'Physc Ward', 'item': 'Tactical Pants'},

    'ER': {'North': 'Hall', 'South': 'Surgery', 'item': 'Holster'},

    'Surgery': {'West': 'ER', 'East': 'Waiting Room', 'item': 'Sidearm'},

    'Waiting Room': {'item': 'ZOMBIE'}}

location = 'Hospital Room'

# function 1

def get_new_state(location, directions):

    new_location = location

    # initialize loop

    for i in rooms:

        if i == location:

            if directions in rooms[i]:

                new_location = rooms[i][directions]

    return new_location

def get_item(location):

    return rooms[location][item]

# function 2

def show_instructions():

    # print instructions for user

    print("Zombie Escape Text Game")

    print("You will need to navigate 8 rooms to collect you 6 items and avoid the Zombie")

    print("You can move North, South, East or West, and other direction is disqualified.")

    print("To add item to your inventory: Take 'item name'")

show_instructions()

inventory = []

while 1:  # gameplay loop

    print('Currently you are in ', location)  # printing state

    print('Current Inventory:', inventory)  # printing inventory

    item = get_item(location)  # calling get_item function

    print('You found item ', item)  # print

    if item == 'ZOMBIE':  # if

        print('AHH BRAINS, ZOMBIE eats your brains! GAME OVER!')

        exit(0)

    direction = input('Choose your Direction: ')  # asking user

    if direction == 'East' or direction == 'West' or direction == 'North' or direction == 'South':  # if

        direction = direction[3:]

        new_state = get_new_state(location, direction)  # calling function

        if new_state == location:  # if

            print('OOPS Wrong Direction Try Another!')  # print

        else:

            state = new_state  # changing state value to new_state

    elif direction == str('Take ' + item):  # if

        if item in inventory:  # if item already present in inventory

            print('Oops item already in your inventory!!')

        else:

            inventory.append(item)  # appending

    else:

        print('Oops Wrong direction!!')  # print

    if len(inventory) == 6:

        print('Wow you collected all your belongs and avoided the ZOMBIE! For now!')  # print

        exit(0)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The error youre encountering is likely due to a missing reference to the item variable in the getitem function To fix this issue you need to ensure th... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!