# Theater Ticket Income Generation # This program displays the amount of income generated from ticket sales for a theater # Written by Beth Mela # Last updated May 5th, 2015 # Define the constants priceSectionA=20 priceSectionB=15 priceSectionC=10 # Have user enter the number of tickets sold in Section A and validate the entry ticketsSoldSectionA= input('Please enter the number of tickets sold in Section A: \n') while ticketsSoldSectionA < 0 or ticketsSoldSectionA > 300: ticketsSoldSectionA = input('The number of tickets sold in Section A is invalid. Please reenter a number between 0 and 300.\n') # Have user enter the number of tickets sold in Section B and validate the entry ticketsSoldSectionB= input('Please enter the number of tickets sold in Section B: \n') while ticketsSoldSectionB <0 or ticketsSoldSectionB >500: ticketsSoldSectionB = input('The number of tickets sold in Section B is invalid. Please reenter a number between 0 and 500.\n') # Have user enter the number of tickets sold in Section C and validate the entry ticketsSoldSectionC= input('Please enter the number of tickets sold in Section C: \n') while ticketsSoldSectionC <0 or ticketsSoldSectionC >200: ticketsSoldSectionC = input('The number of tickets sold in Section C is invalid. Please reenter a number between 0 and 200.\n') # Define the income generation function def ticketIncome(ticketsSoldSectionA, ticketsSoldSectionB, ticketsSoldSectionC): myFunctionsReturnValue = float(ticketsSoldSectionA * priceSectionA) + float(ticketsSoldSectionB * priceSectionB) + float(ticketsSoldSectionC * priceSectionC) return myFunctionsReturnValue # Calculate the income from ticket sales and print the results totalTicketIncome= ticketIncome(ticketsSoldSectionA, ticketsSoldSectionB, ticketsSoldSectionC); print('The number of tickets sold in Section A is: {}.'.format(ticketsSoldSectionA)) print('The number of tickets sold in Section B is: {}.'.format(ticketsSoldSectionB)) print('The number of tickets sold in Section C is: {}.'.format(ticketsSoldSectionC)) print("The total income generated from ticket sales is ${:,.2f}.".format(float(totalTicketIncome)))
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