""" program to calculate pay from user inputted hours work and pay rate. Takes overtime pay into consideration. Uses a defined function to calculate pay. """ def pay_rate (hours, rate): if hours <= 40: pay = hours * rate elif hours > 40: pay = (40 * rate) + (hours - 40) * 1.5 * rate return pay noProb = False while noProb == False: inp_hours = raw_input("How many hours were worked? ") try: hours = float(inp_hours) noProb = True except: print 'Enter hours as a number.' noProb = False while noProb == False: inp_rate = raw_input("What is the hourly rate? ") try: rate = float(inp_rate) noProb = True except: print 'Enter pay rate as a number.' print pay_rate(hours, rate)
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