Python help. Getting error on line 26. Correct the error. # dictionary of rooms and items rooms
Question:
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)