Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Currently working on IT-140. I have attempted to make a dictionary so I can move through all the rooms. The problem is I can only
Currently working on IT-140. I have attempted to make a dictionary so I can move through all the rooms. The problem is I can only move north then east. If i attempt to make amove any other direction it tells me there is no room there. Please help # MoveBetweenRooms function # this function is used to return the room in the given direction def MoveBetweenRooms(rooms, currentRoom, direction): # get the current room details room_config = rooms[currentRoom] # if another room available in the given direction if direction.title() in room_config: return room_config[direction.title()] else: return False if __name__ == "__main__": # room details rooms = { 'Great Hall': {'south': 'Armory'}, 'Armory': {'north': 'Great Hall', 'east': 'Brewery'}, 'Great Hall': {'west': 'Computer Room'}, 'Great Hall': {'east': 'Laundry Room'}, 'Great Hall': {'north': 'Basement'}, 'Basement': {'south': 'Great Hall', 'east': 'Bathroom'}, 'Bathroom': {'west': 'Basement'}, 'Laundry Room': {'west': 'Great Hall', 'north': 'Garage'} } # available directions directions = ['north', 'south', 'east', 'west'] # start the player in the Hall currentRoom = 'Great Hall' command = '' # start an infinite while loop while True: # display the current room print() print("*" * 40) print("You are in {}".format(currentRoom)) # ask user to enter command command = input("enter direction (north/south/east/west) or exit: ") # if user enters exit if command.lower() == 'exit': print("Exit from the rooms!") break # if invalid command entered elif command.lower() not in directions: print("invalid command") else: # get the new room in the direction given newRoom = MoveBetweenRooms(rooms, currentRoom, command) # if room is available in the direction if newRoom: currentRoom = newRoom print("Found {} in the {}".format(currentRoom, command.lower())) else:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started