More on this book
Community
Kindle Notes & Highlights
by
Eric Matthes
admission price. This code produces the same output as the previous example, but the purpose of the if-elif-else chain is narrower. Instead of determining a price and displaying a message, it simply determines the admission price. In addition to being more efficient, this revised code is easier to modify than the original approach. To change the text of the output message, you would need to change only one print() call rather than three separate print() calls. Using Multiple elif Blocks You can use as many elif blocks in your code as you like. For example, if the amusement park were to
...more
pizza! In summary, if you want only one block of code to run, use an
or 'red'. Write an if statement to test whether the alien’s color is green. If it is, print a message that the player just earned 5 points. Write one
Alien Colors #2: Choose a color for an alien as you did in Exercise 5-3, and write an
that runs the else block. 5-5. Alien Colors #3: Turn your if-else chain from Exercise 5-4 into an
that the person is a teenager. If the person is at least 20 years old but less than 65, print a message

