ARTICLE AD BOX
hours = input("Enter hours: ")
try:
hours = float(hours)
except:
print('Please enter a valid number')
quit()
rate = input("Enter rate: ")
try:
rate = float(rate)
except:
print('Please enter a valid number')
quit()
if hours > 40 :
overtime = hours - 40
overpay = overtime * (rate*1.5) + (40*rate)
print("Pay: " + str(overpay))
else :
pay = hours * rate
print("Pay: " + str(pay))
I had to make a program for the following exercises:
Exercise 1: Rewrite your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours.
2: Rewrite your pay program using try and except so that your program handles non-numeric input gracefully by printing a message and exiting the program
Im a complete beginner and i want to learn python. This code works but i feel like there could be a much easier way to do this. Im not sure but i feel like there is and i was wondering if anyone could help me with what i could do to make this more simple but still work properly. If this is a decent piece of code id be happy to hear that too :) Thank you.
