Question: 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.

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

Rewrite the showRoom method more optimally by using elif.

if (room "Porch"): showPorch () elif (room "Kitchen"): showkitchen()

Step by Step Solution

3.46 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

def showRoomroom printNow if room ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Computing and Programming in Pytho Questions!