Python Crash Course, 3rd Edition: A Hands-On, Project-Based Introduction to Programming
Rate it:
Open Preview
Kindle Notes & Highlights
21%
Flag icon
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
22%
Flag icon
pizza! In summary, if you want only one block of code to run, use an
22%
Flag icon
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
22%
Flag icon
Alien Colors #2: Choose a color for an alien as you did in Exercise 5-3, and write an
22%
Flag icon
that runs the else block. 5-5. Alien Colors #3: Turn your if-else chain from Exercise 5-4 into an
22%
Flag icon
that the person is a teenager. If the person is at least 20 years old but less than 65, print a message
23%
Flag icon
versions of all existing users.) 5-11. Ordinal Numbers: Ordinal numbers indicate their position in a list, such as
Chris
To Do