Please, I just started learning python and I wrote a program that catches exceptions on user input. Please, can someone give me insight if I did it the correct way. The code below runs well but wondering if my style is usual.
#This little file tries to write a pay computation based on hours worked #and the rate of pay. If hours worked is more than 40 hours, the rate #is multiplied by 1.5 and increased. Hours = input('Enter hours worked:') try: Hours = float(Hours) except: print('Enter a number please!\n') Rate = input('Enter the rate:') try: Rate = float(Rate) except: print('Enter a number please!') if Hours > 40 : Rate = 1.5*Rate Pay = Rate * Hours print('The pay is',Pay)
Thanks. I used two exception blocks, was wondering if there is a way to use just one.