Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def show _ instruction ( ) : print ( ' Welcome Player' ) print ( ' You woke up in a hospital alone. You need

def show_instruction():
print('Welcome Player')
print('You woke up in a hospital alone. You need to find 9 items in the nine rooms.')
print('There is a mutant zombie in one the rooms ,so be weary.')
print('Move commands: North, East, South, West')
print('Add to Inventory: Get Items')
print('-------------------------------------------------------------------------------')
def show_status():
print(f'You are in the {current_room}')
print(f'Inventory: {inventory}')
print('You look around and see', rooms[current_room]['item'])
rooms ={
'Bathroom': {'East': 'Room Six', 'item': 'Shoes'},
'Room Six': {'West': 'Bathroom', 'South': 'Hallway', 'item': 'Clothes'},
'Hallway': {'North': 'Room Six', 'East': 'Backdoor Room ', 'South': 'Staircase', ' West': ' Front Room', 'item': 'Gun'},
'Front Room': {'East': ' Hallway', 'item': 'Backpack'},
'Backdoor Room': {'West': 'Hallway', 'North': 'Morgue Room', 'item': 'Parking Lot key'},
'Morgue Room': {'South': ' Backdoor Room', 'item': 'Car Key'},
'Staircase': {'North': 'Hallway', 'East': 'Basement', 'item': 'Extra bullets'},
'Basement': {'West': 'Staircase', 'East': 'Parking Lot', 'item': 'Canned food and water'},
'Parking Lot': {'West': 'Basement', 'item': 'Mutant Zombie'}
}
def get_new_state(direction_from_user, current_room ):
new_location = current_room
if direction_from_user in rooms[current_room]:
new_location = rooms[current_room][direction_from_user]
else:
print('You hit the wall. Try again')
return new_location
show_instruction()
current_room = 'Room Six'
inventory =[]
while True:
show_status()
direction_from_user = input('Enter a command' '>>').title()
if direction_from_user in ('North', 'East', 'South', 'West'):
new_location = get_new_state(direction_from_user,current_room)
current_room = new_location
elif direction_from_user ==(' Get '+ rooms[current_room]['item']):
if rooms[current_room]['item'] not in inventory:
inventory.append(rooms[current_room]['item'])
print('You picked up {} and put in your inventory'.format(rooms[current_room]['item']))
else:
print('-----------Item already picked up ---------')
elif current_room == 'Parking Lot':
print('CONGRATULATION !!! You successfully got the items, beat the Mutant Zombie, and got out of the hospital')
break
else:
print('Invalid')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

Students also viewed these Databases questions