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 ()
```

Computer Science & Information Technology

You might also like to view...

Information on secondary storage devices is ________ — it’s preserved even when the computer’s power is turned off.

a. volatile b. unstable c. transient d. persistent

Computer Science & Information Technology

To create a link to an anchor, you use the ____ attribute.

A. name B. href C. link D. anchor

Computer Science & Information Technology

Match the following terms to their meanings:

I. A folder within a folder A. Window Snip II. Customizable mini-programs that display continuously B. Quick Launch updated information toolbar III. Used to capture an image and then save or share the image C. gadgets IV. Captures the entire displayed window D. Snipping tool V. Contains shortcuts to frequently used programs E. subfolder

Computer Science & Information Technology

When downloading a file with PHP, you must provide the appropriate XHTML ____________________ to tell the client Web browser that a response contains more than just a Web page.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology