Theater Seating Revenue Calculator with Input Validation

Theater Seating Revenue with Input Validation: 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 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, in python, 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 number that are entered for each section.
Theater Seating Revenue Calculator with Input Validation


The answer


Description:

This Python program calculates the total revenue from ticket sales in a dramatic theater with three sections (A, B, and C), each with different seat counts and prices. The user is prompted to enter the number of tickets sold in each section. The program validates the inputs to ensure they are within the allowed range and then displays the revenue generated from each section and the total income.


Explanation:

  • Each section (A, B, C) has a maximum number of seats: 300, 500, and 200 respectively.

  • The program prompts the user for the number of tickets sold in each section.

  • Input is validated:

    • It must be an integer

    • It cannot be negative

    • It cannot exceed the total available seats in that section

  • The revenue for each section is calculated and displayed, along with the overall total.


Python Code:

python

def get_valid_tickets(section_name, max_seats): while True: try: value = int(input(f"Enter the number of tickets sold in section {section_name} (0 to {max_seats}): ")) if value < 0: print("Number of tickets cannot be negative. Please try again.") elif value > max_seats: print(f"Cannot sell more than {max_seats} tickets in section {section_name}. Please try again.") else: return value except ValueError: print("Invalid input. Please enter an integer.") def main(): # Section info: name: (price, max_seats) sections = { 'A': (20, 300), 'B': (15, 500), 'C': (10, 200) } revenue = {} total_income = 0 for section in sections: price, max_seats = sections[section] sold = get_valid_tickets(section, max_seats) income = sold * price revenue[section] = income total_income += income print("\nRevenue Report") for section in sections: print(f"Section {section} revenue: ${revenue[section]:.2f}") print(f"Total income: ${total_income:.2f}") if __name__ == "__main__": main()

Sample Run:

typescript

Enter the number of tickets sold in section A (0 to 300): 320 Cannot sell more than 300 tickets in section A. Please try again. Enter the number of tickets sold in section A (0 to 300): -5 Number of tickets cannot be negative. Please try again. Enter the number of tickets sold in section A (0 to 300): 150 Enter the number of tickets sold in section B (0 to 500): 250 Enter the number of tickets sold in section C (0 to 200): 100 Revenue Report Section A revenue: $3000.00 Section B revenue: $3750.00 Section C revenue: $1000.00 Total income: $7750.00

📩 Need a similar solution? Email me: adel455@hotmail.com








Previous Post Next Post

Comments

Nepali Graphics - Learn design, Animation, and Progrmming