Westonci.ca makes finding answers easy, with a community of experts ready to provide you with the information you seek. Our Q&A platform offers a seamless experience for finding reliable answers from experts in various disciplines. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.

An airline describes airfare as follows. A normal ticket's base cost is $300. Persons aged 60 or over have a base cost of $290. Children 2 or under have $0 base cost. A carry-on bag costs $10. A first checked bag is free, second is $25, and each additional is $50. Given inputs of age, carry-on (0 or 1), and checked bags (0 or greater), compute the total airfare. Hints: First use an if-else statements to assign airFare with the base cost Use another if statement to update airFare for a carryOn Finally, use another if-else statement to update airFare for checked bags Think carefully about what expression correctly calculates checked bag cost when bags are 3 or more

Sagot :

Answer:

The program in Python is as follows:

age = int(input("Age: "))

carryOn = int(input("Carry on Bags [0 or 1]: "))

checkedBags = int(input("Checked Bags [0 or greater]: "))

airFare = 300

if age >= 60:

   airFare = 290

elif age <= 2:

   airFare = 0

if carryOn ==  1:

   airFare += 10

if checkedBags ==  2:

   airFare += 25

elif checkedBags >  2:

   airFare += 25 + 50 * (checkedBags - 2)

print("Airfare: ",airFare)

Explanation:

This gets input for age

age = int(input("Age: "))

This gets input for carry on bags

carryOn = int(input("Carry on Bags [0 or 1]: "))

This gets input for checked bags

checkedBags = int(input("Checked Bags [0 or greater]: "))

This initializes the base cost to 300

airFare = 300

This updates the base cost to 290 for adults 60 years or older

if age >= 60:

   airFare = 290

This updates the base cost to 0 for children 2 years or younger

elif age <= 2:

   airFare = 0

This updates the airFare if carryOn bag is 1

if carryOn ==  1:

   airFare += 10

if carryOn bag is 0, the airFare remains unchanged

This updates the airFare if checkedBags is 2. The first bag is free; so, only the second is charged

if checkedBags ==  2:

   airFare += 25

This updates the airFare if checkedBags greater than 2. The first bag is free; so, only the second and other bags is charged

elif checkedBags >  2:

   airFare += 25 + 50 * (checkedBags - 2)

if checkedBags is 0 or 1, the airFare remains unchanged

This prints the calculated airFare

print("Airfare: ",airFare)