您的代码包含一些语法和语义错误:布尔值true应该以大写字母True开头。在
编写代码的方式非常重要,并且应该以正确的方式进行格式化,每个指令前的空格是敏感的,即同一块代码的前面应该有相同数量的空格。在
通过在trybloc中使用raise,您创建了一个自定义异常,该异常将始终被执行,并且永远不会到达{}bloc。在
在except关键字之后,有两个选项:输入异常名称,例如:
except ValueError:
print("Non-numeric data found in the file.")或者不指定异常,让它空白
键入代码的正确方法是:while True:
hrs = input ("Enter no.of hrs worked: ")
rate = input ("Enter the rate per hour: ")
try:
hrs = int(hrs)
rate = int(rate)
#raise ValueError("Non numeric value")
except :
print ('Non numeric data found.')
continue
if hrs > 40:
# anything over 40 hrs earns the overtime rate
overtimeRate = 1.5 * rate
overtime = (hrs-40) * overtimeRate
# the remaining 40 hrs will earn the regular rate
hrs = 40
regular=hrs*rate
total_pay=regular+overtime
print(total_pay)
else:
# if you didn't work over 40 hrs, there is no overtime
overtime = 0
total_pay=hrs*rate
print(total_pay)
quit()
希望有帮助!在