Below is a solution that uses a dictionary whose keys are the place locations and whose values are themselves dictionaries with two keys/value pairs: the description of that location and a list of places that one can go next. So a dictionary within a dictionary (dict-ception). For instance, a data structure with one entry in the dictionary might look like this
places = {"Office":{
"description":"The place where you frantically try to get everything ready for class",
"next":["Kitchen", "Bathroom"]
}}
print(places["Office"]["description"]) # Print out the description
The place where you frantically try to get everything ready for class
Some students chose to make the value a list instead of a dictionary, which is fine. The only downside is we now need to use some magic number indices to access the description and next place, so it is stylistically not quite as elegant
places = {"Office":["The place where you frantically try to get everything ready for class", ["Kitchen", "Bathroom"]]}
Matching braces can be a real pain when we have nested lists/dictionaries like this, so I'm going to break it down by starting over and adding elements one at a time
places = {}
places["Office"] = {"description":"The place where you frantically try to get everything ready for class",
"next":["Kitchen", "Bathroom"]}
places["Bathroom"] = {"description":"The place you go when nature calls",
"next":["Office"]}
places["Kitchen"] = {"description":"The place where you heat up frozen food and sometimes (but rarely) cook",
"next":["Office", "Upstairs Bedroom", "Outside"]}
places["Outside"] = {"description":"The place you will go when there is a COVID vaccine",
"next":["Kitchen"]}
places["Upstairs Bedroom"] = {"description":"The place you go rarely when you've finished your work for the day",
"next":["Kitchen", "Upstairs Bathroom"]}
places["Upstairs Bathroom"] = {"description":"The higher altitude version of the place you go when nature calls",
"next":["Kitchen", "Upstairs Bedroom"]}
Finally, we can put this together in a while loop that's our game. We'll make the game end when we end up outside
start = "Office"
end = "Outside"
state = start
while state != end:
print("You are at ", state, ".", places[state]["description"])
nxt = ""
while len(nxt) == 0: # Keep looping until we get a valid input
print("Please type your next destination", places[state]["next"], ":")
nxt = input()
if nxt in places[state]["next"]:
state = nxt
else:
print("Invalid next location!")
nxt = ""
print("You have arrived at ", end, ".", places[end]["description"])
You are at Office . The place where you frantically try to get everything ready for class Please type your next destination ['Kitchen', 'Bathroom'] : Bathroom You are at Bathroom . The place you go when nature calls Please type your next destination ['Office'] : Office You are at Office . The place where you frantically try to get everything ready for class Please type your next destination ['Kitchen', 'Bathroom'] : Kitchen You are at Kitchen . The place where you heat up frozen food and sometimes (but rarely) cook Please type your next destination ['Office', 'Upstairs Bedroom', 'Outside'] : Office You are at Office . The place where you frantically try to get everything ready for class Please type your next destination ['Kitchen', 'Bathroom'] : Kitchen You are at Kitchen . The place where you heat up frozen food and sometimes (but rarely) cook Please type your next destination ['Office', 'Upstairs Bedroom', 'Outside'] : blah Invalid next location! Please type your next destination ['Office', 'Upstairs Bedroom', 'Outside'] : Upstairs bedroom Invalid next location! Please type your next destination ['Office', 'Upstairs Bedroom', 'Outside'] : Upstairs Bedroom You are at Upstairs Bedroom . The place you go rarely when you've finished your work for the day Please type your next destination ['Kitchen', 'Upstairs Bathroom'] : Upstairs Bathroom You are at Upstairs Bathroom . The higher altitude version of the place you go when nature calls Please type your next destination ['Kitchen', 'Upstairs Bedroom'] : Upstairs Bedroom You are at Upstairs Bedroom . The place you go rarely when you've finished your work for the day Please type your next destination ['Kitchen', 'Upstairs Bathroom'] : Kitchen You are at Kitchen . The place where you heat up frozen food and sometimes (but rarely) cook Please type your next destination ['Office', 'Upstairs Bedroom', 'Outside'] : Outside You have arrived at Outside . The place you will go when there is a COVID vaccine