64.8k views
8 votes
Modify your previous exercise to determine if the user can ride a rollercoaster. To ride the rollercoaster, you must be at least 42 inches tall. You must also be at least 9 years old. Ask the user how tall and how old they are. Use ONE if-else to determine if the user can ride the rollercoaster. Note how much cleaner this is and how much less repetition this method has.

1 Answer

11 votes

Answer:

In Python:

age = int(input("How old are you? "))

height = float(input("How tall are you (inches)? "))

if age>=9 and height >= 42:

print("You can ride the roller coaster")

else:

print("You ca'nt ride the roller coaster")

Step-by-step explanation:

The code segment of the "previous exercise" is not given; so, I rewrite the program from scratch using python.

And using the solution I provided, you'll have an idea of how to write the expected code If the "previous exercise" is not written in python,

This line prompts user for age

age = int(input("How old are you? "))

This line prompts user for height

height = float(input("How tall are you (inches)? "))

This checks if user is at least 9 years old and at least 42 inches tall

if age>=9 and height >= 42:

If true, the user gets to ride the roller coaster

print("You can ride the roller coaster")

else:

If otherwise, the user will not ride the roller coaster

print("You ca'nt ride the roller coaster")

User Jason Harrison
by
4.3k points