Getting NameError and Traceback errors when trying Try and Except

9 Views Asked by At

Here is my code:

import sys
try:
    inp1 = input("Enter Hours: ")
    Hours = float(inp1)
    inp2 = input("Enter Rate: ")
    Rate = float(inp2)
except:
    print("Error, Please enter numeric input")
    quit()

if Hours <= 40:
    Pay = Hours * Rate
    print("Your pay is: ", Pay)
elif Hours > 40:
    Pay = (Rate * 40) + ((Hours - 40) * Rate * 1.5 )
    print("You worked over time. Your pay is: ", Pay)

WHy am I getting Traceback (most recent call last) and NameError: name 'Hours' is not defined?

Learning Try and Except.

0

There are 0 best solutions below