# Lee Her # CIS 122 # Ch.7 Program Ex 2: Theater Seating Revenue with Input Validation. # Last modified on 04/9/2015 #Declare variables #seat cost seatA = 20 seatB = 15 seatC = 10 #tickets sectionA=300 sectionB=500 sectionC=200 #Get tickets and validate ticketA = int(input('\nPlease enter tickets sold for section A. ')) while ticketA > sectionA: ticketA = int(input('\n{} is Invalid, please re-enter.'.format(ticketA))) if ticketA <= sectionA: print '\nSold tickets: {}'.format(ticketA) ticketB = int(input('\nPlease enter tickets sold for section B. ')) while ticketB > sectionB: ticketB = int(input('\n{} is Invalid, please re-enter.'.format(ticketB))) if ticketB <= sectionB: print '\nSold tickets: {}'.format(ticketB) ticketC = int(input('\nPlease enter tickets sold for section C. ')) while ticketC > sectionC: ticketC = int(input('\n{} is Invalid, please re-enter.'.format(ticketC))) if ticketC <= sectionC: print '\nSold tickets: {}'.format(ticketC) print #Functions for ticket generating def sectionAval(ticketA, sectionA): if ticketA < sectionA: sectionA = sectionA - ticketA print 'There are',sectionA,'tickets remaining in section A.' else: print 'There are no more tickets available in secion A.' incomeA = float(ticketA * seatA) print 'Total income generated for section A: ${}'.format(incomeA) sectionAval(ticketA, sectionA) print '---------------------------------------------------------------------' def sectionBval(ticketB, sectionB): if ticketB < sectionB: sectionB = sectionB - ticketB print 'There are',sectionB,'tickets remaining in section B.' else: print 'There are no more tickets available in secion B.' incomeB = float(ticketB * seatB) print 'Total income generated for section B: ${}'.format(incomeB) sectionBval(ticketB, sectionB) print '---------------------------------------------------------------------' def sectionCval(ticketC, sectionC): if ticketC < sectionC: sectionC = sectionC - ticketC print 'There are',sectionC,'tickets remaining in section C.' else: print 'There are no more tickets available in secion C.' incomeC = float(ticketC * seatC) print 'Total income generated for section C: ${}'.format(incomeC) sectionCval(ticketC, sectionC) #END
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