# program to compute pay; done at theend of class on Jan 2019 # # Given the number of hours worked, the rate of pay per hour, and # the overtime multiplier, compute the amount of pay # # Matt Bishop, MHI 289I, Winter 2019 try: hours = int(input("Number of hours worked> ")) payperhour = float(input("How much money per hour of work> ")) overfactor = float(input("What is the overtime work factor> ")) except: print("One of what you typed is wrong -- numbers, please!") else: # sanity check #1: hours worked must be non-negative if hours < 0: print("You worked negative hours? (You said", hours, ")") # sanity check #2: rate of pay per hour must be non-negative if payperhour < 0: print("You paid them to work for them? (You said", payperhour, ")") # sanity check #3: increase in pay for overtime must be positive if overfactor < 1: print("Overtime is less than regular hours (You said", overfactor, ")") # figure out the numbers of regular hours and overtime hours overtime = hours - 40 if overtime > 0: regular = 40 elif overtime < 0: overtime = 0 regular = hours # now compute the pay for regular and overtime work # and add it together to get the total regpay = regular * payperhour overpay = overtime * payperhour * overfactor total = regpay + overpay # now print out the result print("You worked", regular, "hours of regular time and", overtime, end=" ") print("hours of overtime; your pay is $%.2f" % total)