Typically, one does not optimize a program (make it run faster or with less use of memory) until after it is running, well-debugged, and well-tested. (Of course, you still have to test again after each optimizing modification.) Here is an optimization that we could make to the adventure game. Currently, showRoom compares the room variable to each possible room—even if it matched earlier. Python gives us a way of only testing once, by using an elif instead of later if statements. The statement elif means “else if.” You only test the elif statement if the earlier if was false. You may have as many elif statements as you like after an if. You might use it like this:
```
if (room == ‘‘Porch’’):
showPorch()
elif (room == ‘‘Kitchen’’):
showKitchen()
```
Rewrite the showRoom method more optimally by using elif.
```
def showRoom(room):
printNow("===========")
if room == "Porch":
showPorch()
elif room == "Entryway":
showEntryway()
elif room == "Kitchen":
showKitchen()
elif room == "LivingRoom":
showLR ()
elif room == "DiningRoom":
showDR ()
```
You might also like to view...
Virtual machine ________ are used to capture the state, data, and configuration of a VM
Fill in the blank(s) with correct word
Give the following class template, what changes need to be made to the default constructor definition?
template