Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Having trouble with project 2 game. Can anyone help me out with this error i keep getting? KeyError: 'Item' # declaration rooms = { 'Start':

Having trouble with project 2 game. Can anyone help me out with this error i keep getting?

KeyError: 'Item'

image text in transcribed # declaration rooms = { 'Start': {'North': 'Payroll'}, 'Payroll': {'North': 'Dispatch', 'South': 'Start', 'Item': 'Money'}, 'Dispatch': {'East': 'Parking Garage', 'South': 'Payroll', 'Item': 'Truck Key'}, 'Parking garage': {'South': 'Warehouse', 'West': 'Dispatch', 'Item': 'Delivery Truck'}, 'Warehouse': {'South': 'House1', 'North': 'Parking garage', 'Item': '3 Packages'}, 'House1': {'South': 'House2', 'North': 'Warehouse'}, 'House2': {'South': 'House3', 'North': 'House1'}, 'House3': {'South': 'Gas Station', 'North': 'House2'}, 'Gas Station': {'West': 'Highway', 'North': 'House3'}, 'Highway': {'Item': 'Rain'} } # function def get_new_state(state, direction): new_state = state for i in rooms: #loop if i == state: if direction in rooms[i]: new_state = rooms[i][direction] # assigning a new state return new_state #return def get_item(state): return rooms[state]["Item"] #returning Item value #function def show_instructions(): #print a main menu and the commands print("Delivery Trucking Game") print("Collect: Money, 1 Key,1 Truck, and 3 packages to win the game or get washed out by the rain.") print("Move commands: go South, go North, go East, go West.") print("Add to Inventory: get 'item name'") state = 'Start' show_instructions() #calling function inventory = [] while 1: # gameplay loop print('You are in ', state) # printing state print('Inventory:', inventory) # printing inventory Item = get_item(state) # calling the get_item function print('You see a', item) if Item == 'Rain': print('Washed out for the day...Game Over!') exit(0) direction = input('Enter direction you want to go: ') #ask the user for the direction if (direction == 'go South' or direction == 'go North' or direction == 'go East' or direction == 'go West'): direction = direction[3:] new_state = get_new_state(state, direction) #calling the function if new_state == state: print('Cant use that direction, try again') else: state = new_state #change the state value to the new_state elif direction == str('get '+item): if item in inventory: #if the item is already present in the inventory print('Item already taken, go to another room.') else: inventory.append(item) else: print('Invalid Direction') if len(inventory) == 6: print('Congratulations! You successfully dropped off the packages before the rain! Get paid for the day and go home.') exit(0)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

What is a market? What are the requirements for a market

Answered: 1 week ago