"""====================================================================== Program: Theatre Revenue Calculator Author: Chris Brockamp Date: May 9, 2015 Dev Env: PyCharm Community Edition 4.0.6 Description: Calculates the gross sales for a theatre with multiple seating ======================================================================""" #_declare constants______________________________________________________ # dollars SECTION_A_TICKET_PRICE = 20 SECTION_B_TICKET_PRICE = 15 SECTION_C_TICKET_PRICE = 10 # tickets SECTION_A_LIMIT = 300 SECTION_B_LIMIT = 500 SECTION_C_LIMIT = 200 #_function definitions____________________________________________________ def validate_section_A(section): while section < 0 or section > SECTION_A_LIMIT: print "\nERROR: You entered an invalid number of tickets sold for section A..." section = input("How many tickets were sold in section A: ") else: return section def validate_section_B(section): while section < 0 or section > SECTION_B_LIMIT: print "\nERROR: You entered an invalid number of tickets sold for section B..." section = input("How many tickets were sold in section B: ") else: return section def validate_section_C(section): while section < 0 or section > SECTION_C_LIMIT: print "\nERROR: You entered an invalid number of tickets sold for section C..." section = input("How many tickets were sold in section C: ") else: return section def calculate_total_sales(section_A, section_B, section_C): section_A *= SECTION_A_TICKET_PRICE section_B *= SECTION_B_TICKET_PRICE section_C *= SECTION_C_TICKET_PRICE return section_A + section_B + section_C def display_total_sales(total): print("\n***************************") print("Total Sales = $%.2f") % float(total) print("***************************") #_Main_____________________________________________________________________ section_a = input("How many tickets were sold in section A: ") validate_section_A(section_a) section_b = input("How many tickets were sold in section B: ") validate_section_B(section_b) section_c = input("How many tickets were sold in section C: ") validate_section_C(section_c) total_sales = calculate_total_sales(section_a, section_b, section_c) display_total_sales(total_sales)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question