#Payroll Program with Input Validation print("This program calculates your gross pay") #Get payrate and hours worked payrate = float(input("What is your hourly payrate, in dollars?")) hours = float(input("How many hours did you work this week?")) grosspay = payrate * hours #Validate payrate and hours worked; display gross pay if input is valid if payrate < 7.50 : print ( "Invalid payrate" ) elif payrate > 18.25 : print ( "Invalid payrate") elif hours < 0 : print ( "Invalid hours" ) print ( "Hours reported must be beween 0 and 40" ) elif hours > 40 : print ( "Invalid hours" ) print ( "Hours reported must be beween 0 and 40" ) else : print( " Your gross pay is ${:,.2f}".format(grosspay))
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