Python Programming for Beginners: A Kid's Guide to Coding Fundamentals by Patricia Foster

Python Programming for Beginners: A Kid's Guide to Coding Fundamentals by Patricia Foster

Author:Patricia Foster [Foster, Patricia]
Language: eng
Format: azw3, epub, pdf
ISBN: 9781646113897
Publisher: Rockridge Press
Published: 2020-10-19T16:00:00+00:00


Roller Coaster Challenge

A group of friends are headed to a theme park. However, some rides (like the Spinning Typhoon and the Rocket Blaster 5000) have a minimum height. Using an if-elif-else statement, let’s find the scariest roller coaster that the whole group can ride together.

To start our code, let’s put everyone’s height (in inches) in a list. The order is completely random:

heights = [52, 54, 41, 62, 55, 49, 65]

If the shortest person in the group can ride a rollercoaster, then so can everyone else. Since we’ve stored the heights in a list, we can use the min function to find the shortest height:

min_height = min(heights)

The min function returns the smallest number in the list. Then, we store the result in the “min_height” variable.

Time to pick a roller coaster! The three options are:

1.Rumbling Log Ride: no height restrictions

2.Rocket Blaster 5000: 60" and over

3.Spinning Typhoon: 40” and over

When creating our conditional, order matters! Since the friends want to ride the scariest roller coaster possible, we want to start with the ride that has the tallest height requirement: the Rocket Blaster 5000.

if min_height >= 60:

print("You can ride the Rocket Blaster 5000!")

If the smallest friend is under 60", the group will have to look for other options. The next scariest roller coaster is the Spinning Typhoon:

elif min_height >= 40:

print("You can ride the Spinning Typhoon!")

If neither of those conditions are True, there’s always the roller coaster with no height restriction: the Rumbling Log Ride. Since we’re not checking a condition, we can use an else instead of an elif:

else:

print("You can ride the Rumbling Log Ride!")

Our program is done! Make sure that all the lines of code inside your conditionals are indented, and then run your program.

CODE COMPLETE!

heights = [52, 54, 41, 62, 55, 49, 65]

min_height = min(heights)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.