# ------------------------------------------------------------ #Student: Austin Wells #Class: CIS122 #Date: 5/4/2015 #Program Title: Chapter 7 Programming Excercise 1.py #(Payroll Program with Input Validation) #Program Description: The program prompts the user for an employees hourly pay rate and # number of hours worked and displays the employess gross pay. # ------------------------------------------------------------ # Prints out the score and letter grade def printStuff(printStr1, grossPay): print '{} ${}' .format(printStr1, grossPay) # prompts user for input. def promptForInput(numRepetition = 1, *strPrompt): argArray = [] for i in range(0,numRepetition): argArray.append(float(raw_input(strPrompt[i] + ": "))) print '{}' .format(argArray[i]) return argArray #calculates the average of the scores def calcGrossPay(argInput): grossPayVar = argInput[0] * argInput[1] return grossPayVar #main driver function def main(): try: arrayArg = promptForInput(2,"Please enter an employee's hourly pay rate","Please enter an employee's number of hours") while ((arrayArg[0] < 7.5 or arrayArg[0] > 18.25) or (arrayArg[1] < 0 or arrayArg[1] > 40)): if((arrayArg[0] < 7.5 or arrayArg[0] > 18.25) and (arrayArg[1] < 0 or arrayArg[1] > 40)): print("The hourly pay rate is not between $7.50 and $18.25 and number of hours entered is not between" " 0 and 40. Please enter appropriate values") arrayArg = promptForInput(2,"Please enter an employee's hourly pay rate","Please enter an employee's number of hours") elif(arrayArg[0] < 7.5 or arrayArg[0] > 18.25): print("An hourly pay rate was entered that is not between $7.50 and $18.25. Please enter an appropriate amount.") arrayArg = promptForInput(2,"Please enter an employee's hourly pay rate","Please enter an employee's number of hours") elif((arrayArg[1] < 0 or arrayArg[1] > 40)): print("The number of hours entered is not between 0 and 40. Please enter an appropriate number of hours.") arrayArg = promptForInput(2,"Please enter an employee's hourly pay rate","Please enter an employee's number of hours") printStuff("The employees gross pay is ",calcGrossPay(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