225k views
1 vote
Write a program that determines 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 a nested if statement to determine if they can ride the rollercoaster. If they can, print 'Welcome aboard!' If they cannot, print 'Sorry, you are not eligible to ride'.

1 Answer

6 votes

Final answer:

The question requires writing a program to determine eligibility to ride a rollercoaster based on height and age. The program uses a nested if statement to check if the user is at least 42 inches tall and at least 9 years old and outputs whether the user can ride or not.

Step-by-step explanation:

We'll write a simple program to determine if a user can ride a rollercoaster based on their height and age. The program will ask the user for their height (in inches) and their age, and it will use a nested if statement to verify if both conditions are met: being at least 42 inches tall and being at least 9 years old. If the user meets both criteria, the program will print a welcoming message. Otherwise, it will print a message indicating the user is not eligible to ride the rollercoaster.

Sample Python Program:

height = int(input("How tall are you in inches? "))
age = int(input("How old are you? "))

if height >= 42:
if age >= 9:
print('Welcome aboard!')
else:
print('Sorry, you are not eligible to ride')
else:
print('Sorry, you are not eligible to ride')

In this example, we first check if the height condition is met. If it is, we then check the age condition within the nested if statement. Only if both conditions are satisfied will the system print 'Welcome aboard!'. If any of the conditions are not met, 'Sorry, you are not eligible to ride' will be printed instead.

User Hermannk
by
8.1k points