6.8k views
5 votes
A dramatic theater has three seating sections, and it charges the following prices for tickets in each section: section A seats cost $20 each, section B seats cost $15 each, and section C seats cost $10 each. The theater has 300 seats in section A, 500 seats in section B, and 200 seats in section C. Design a program that asks for the number of tickets sold in each section and then displays the amount of income generated from ticket sales. The program should validate the numbers that are entered for each section.

User Jmt
by
5.0k points

1 Answer

5 votes

Answer:

  1. section_a_cost = 20
  2. section_b_cost = 15
  3. section_c_cost = 10
  4. seatA = int(input("Input number of ticket sold in Section A: "))
  5. seatB = int(input("Input number of ticket sold in Section B: "))
  6. seatC = int(input("Input number of ticket sold in Section C: "))
  7. if(seatA < 0 or seatA > 300):
  8. print("Input Section A must be between 0 - 300!")
  9. elif(seatB < 0 or seatB > 500):
  10. print("Input Section B must be between 0 - 500!")
  11. elif(seatC < 0 or seatC > 200):
  12. print("Input Section C must be between 0 - 200!")
  13. else:
  14. income = (seatA * section_a_cost) + (seatB * section_b_cost) + (seatC * section_c_cost)
  15. print("Total income from ticket sales: $" + str(income))

Step-by-step explanation:

The solution code is written in Python 3.

Firstly, create three variables to hold the ticket cost for each section A, B and C (Line 1 - 3).

Next, prompt user to input number of ticket sold in Section A, B and C (Line 5 -7).

Validate the input value by using if else if statement to check if the input fall within the range of maximum seat in each section (Line 9 -14). If not, display error message. If the input pass all the validation, the program will calculate the total income from the ticket sales and display the result (Line 16 - 17).

User Murzagurskiy
by
4.5k points