# Theater Seating Revenue - Input Validation # Week 6, Ch 7, Ex 2 # Written by Greg Lamb # Last modified: 05/04/2015 #Section A qty <=300 #Section B qty <=500 #Section C qty <=200 #Constants: priceSectionA = 20 priceSectionB = 15 priceSectionC = 10 #Variables seatsA=0 seatsB=0 seatsC=0 seatsGood = False numTries = 0 while(seatsGood==False and numTries <3): numTries += 1 #How many tickets sold in Section A? seatsA = input("Enter the number of tickets sold for Section A: ") #Validate seats in section A input if seatsA > 300: print("Section A has 300 seats. Re-enter the tickets sold for Section A: ") if numTries >=3: seatsA = 0 else: print("{} tickets were sold in Section A".format(seatsA)) seatsGood = True #How many tickets sold in Section B? seatsB = input("Enter the number of tickets sold for Section B: ") #Validate seats in section B input if seatsB > 500: print("Section B has 500 seats. Re-enter the tickes sold for Section B: ") if numTries >=3: seatsB = 0 else: print("{} tickets were sold in Section B".format(seatsB)) seatsGood = True #How many tickets sold in Section B? seatsC = input("Enter the number of tickets sold for Section C: ") #Validate seats in section C input if seatsC > 200: print("Section C has 200 seats. Re-enter the tickes sold for Section C: ") if numTries >=3: seatsC = 0 else: print("{} tickets were sold in Section C".format(seatsC)) seatsGood = True def calcRevenue(seatsA, seatsB, seatsC): return (priceSectionA * seatsA) + (priceSectionB * seatsB) + (priceSectionC * seatsC) #Total revenue from ticket sales print("The total revenue from ticket sales is: ${:,.2f}".format(calcRevenue(seatsA, seatsB, seatsC)))
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