# Payroll Program and Input Validation # This program validates the hourly wage and number of hours entered and then calculates the gross pay # Written by Beth Mela # Last updated May 4th, 2015 # Have user enter the number of hours worked and validate the entry hours = input('Please enter the number of hours worked with a value between 0 and 40 hours.\n') while hours < 0 or hours > 40: hours = input('The number of hours entered is invalid. Please reenter the number of hours worked with a value between 0 and 40.\n') # Have user enter the hourly pay rate and validate the entry pay = input('Please enter the hourly pay rate with a value between $7.50 and $18.25.\n') while pay < 7.5 or pay > 18.25: pay = input('The hourly pay rate entered is invalid. Please reenter the hourly pay rate with a value between $7.50 and $18.25.\n') # Define grossPay function def grossPay(pay,hours): myFunctionsReturnValue= float(pay) * float(hours) return myFunctionsReturnValue # Calculate Gross Pay totalGrossPay= grossPay(pay,hours); print('The number of hours entered is {} hours.'.format(hours)) print('The hourly pay rate entered is ${:,.2f}.'.format(pay)) print("The employee's gross pay is ${:,.2f}.".format(float(totalGrossPay)))
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