# ------------------------------------------------------------ #Student: Austin Wells #Class: CIS122 #Date: 5/4/2015 #Program Title: Chapter 7 Programming Excercise 2.py #(Theater Seating Revenue with Input Validation) #Program Description: The program prompts the user for #the number of tickets sold in each section and displays the income generated. # ------------------------------------------------------------ # Prints out generated income def printStuff(printStr1, genIncome): print '{} ${:0,.2f}' .format(printStr1, genIncome) # prompts user for input. def promptForInput(numRepetition = 1, *strPrompt): argArray = [] for i in range(0,numRepetition): argArray.append(int(raw_input(strPrompt[i] + ": "))) print '{}' .format(argArray[i]) return argArray #calculates income generated def calcIncomeGenerated(argInput): incomeGenerated = [] sectionAVal = argInput[0] * 20 sectionBVal = argInput[1] * 15 sectionCVal = argInput[2] * 10 incomeGenerated = sectionAVal + sectionBVal + sectionCVal return incomeGenerated #main driver function def main(): try: arrayArg = promptForInput(3,"Please enter ticket number for section A","Please enter ticket number for section B","Please enter ticket number for section C") while ((arrayArg[0] > 300 or arrayArg[1] > 500 or arrayArg[2] > 200)): if((arrayArg[0] > 300 and arrayArg[1] > 500 and arrayArg[2] > 200)): print("The number of tickets entered for sections A, B and C exceed the maximum available tickets per section") arrayArg = promptForInput(3,"Please enter ticket number for section A","Please enter ticket number for section B","Please enter ticket number for section C") elif(arrayArg[1] > 500): print("The number of tickets entered for sections B exceed the maximum available tickets for the section") arrayArg = promptForInput(3,"Please enter ticket number for section A","Please enter ticket number for section B","Please enter ticket number for section C") elif(arrayArg[2] > 200): print("The number of tickets entered for sections C exceed the maximum available tickets for the section") arrayArg = promptForInput(3,"Please enter ticket number for section A","Please enter ticket number for section B","Please enter ticket number for section C") printStuff("The total income generated is ",calcIncomeGenerated(arrayArg)) except (EOFError): print '\n\nInvalid input. You have forgotten to add input. Please Reset program and Please enter an integer' main()
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