Your first if cases are still of type str
.
You should also convert your input to an int
, before comparing them.
Just took the code that you wrote and moved your str -> int castings
up, just before all the if cases. Now your input is converted to an int
before it's used in the if cases.
This code will work fine if all inputs are garuanteed to be numeric. Otherwise, you should add some error catching.
inp = input('Enter Hours: ')
inp2 = input ('Enter Rate: ')
Hours = int (inp)
Rate = int (inp2)
if Hours <= 0 :
print ('Please inter a valid number')
if Hours <= 40 :
Pay = Hours * Rate
print ('Pay= ', pay)
elif Hours > 40 :
Hours = int (Hours)
Rate = int (Rate)
Pay = (Hours * 10) + (Rate - 10) * (1.5)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…