I'm trying to add an error message if the input is non-numeric. I've tried try
/except
and now trying if
/else
but both don't get activated (e.g. if the user enters "ten percent", there is an error output versus my error message)
The first one calculates grade based on a percentage input. The second is supposed to calculate pay.
grade=eval(input("Enter Score:"))
try:
if(grade<0 or grade>1):
print("Bad Score")
elif(grade>=0.9):
print("A")
elif(grade<=0.9 and grade>=0.8):
print("B")
elif(grade<=0.8 and grade>=0.7):
print("C")
elif(grade<=0.7 and grade>=0.6):
print("D")
else:
print("F")
except:
print("Bad score")
Hours=eval(input('Please enter hours worked: '))
Rate=eval(input('Please enter pay per hour: '))
if(Hours<=40 and Hours>=0):
Pay=Hours*Rate
elif(Hours>40):
Pay=((Hours-40)*(1.5*Rate))+(40*Rate)
print('Your pay should be $',Pay)
else:
print('Error. Please enter a Numeric Value')
Edited for formatting... code was correct in the original post but had to indent to create code grey box, creating incorrect indents.
Thank you once again!