A function like pickRoom is hard to read with all the nested if statements. It can be made clearer with appropriate use of comments to explain what each section of the code is doing—checking the room, then checking the possible directions in the room. Add comments to pickRoom to make it easier to read.

What will be an ideal response?


```
def pickRoom(direction , room):
#This code handles the command that quits the game
if (direction == "quit") or (direction == "exit"):
printNow("Goodbye!")
return "Exit"
#This section handles the help command which displays the introduction text again
if direction == "help":
showIntroduction()
return room
#The section below checks each room, then checks the possible directions in the room
#"Porch" room direction handling
if room == "Porch":
if direction == "north":
return "Entryway"
#"Entryway" room direction handling
if room == "Entryway":
if direction == "north":
return "Kitchen"
if direction == "east":
return "LivingRoom"
if direction == "south":
return "Porch"
#"Kitchen" room direction handling
if room == "Kitchen":
if direction == "east":
return "DiningRoom"
if direction == "south":
return "Entryway"
#"Livingroom" room direction handling
if room == "LivingRoom":
if direction == "west":
return "Entryway"
if direction == "north":
return "DiningRoom"
#"DiningRoom" room direction handling
if room == "DiningRoom":
if direction == "west":
return "Kitchen"
if direction == "south":
return "LivingRoom"

#This last section handles invalid commands
printNow("You can't (or don't want to) go in that direction.")
return room
```

Computer Science & Information Technology

You might also like to view...

Which of the following is a valid selector for a class named menu?

a) menu b) #menu c) .menu d) > menu

Computer Science & Information Technology

What other methods do all classes inherit from the Object class?

What will be an ideal response?

Computer Science & Information Technology

Click the Format Painter one time to use its multiple-use feature to repeatedly copy formatting to multiple selections

Indicate whether the statement is true or false

Computer Science & Information Technology

Which of the following is NOT a step in changing the exact measurement of an object?

A) Click the Object contextual tab. B) Select the object. C) Change the Shape Height and/or Shape Weight in the Size group. D) You can open the Format Picture pane from the Size Dialog Box Launcher.

Computer Science & Information Technology