asked 183k views
5 votes
Write a program that takes in a string that holds the values "dyy' or "night' and an integer that holds a person's age, and outputs a movie ticket price Movie prices are free for everyone under the age of 4 . Daytime prices are S8 for everyone age 4 or higher. Nighttime prices are $12 for ages 4−16,$15 for ages 17−54 and $13 for ages 55 and above:

asked
User Luuuud
by
8.0k points

1 Answer

3 votes

Final answer:

To write a program that calculates movie ticket prices based on age and time, you can use if-else statements to apply the given conditions. The code example provided is in Python and demonstrates how to calculate the ticket price based on the 'day' or 'night' input and the person's age.

Step-by-step explanation:

To write a program that takes in a string representing 'day' or 'night' and an integer representing a person's age, you can use if-else statements to determine the movie ticket price based on the given conditions. Here's an example in Python:

def calculate_ticket_price(time, age):
if time == 'day' and age >= 4:
return 8
elif time == 'night':
if age >= 4 and age <= 16:
return 12
elif age >= 17 and age <= 54:
return 15
elif age >= 55:
return 13
else:
return 0

# Example usage:
time = 'day'
age = 10
price = calculate_ticket_price(time, age)
print('The ticket price is $' + str(price))
answered
User Mike Pall
by
7.8k points

No related questions found