请告诉我它有什么毛病。因为当我运行这个程序时,它会显示一个错误。在“if hrs>;40”行中显示语法错误!在
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 enter code hereValueError as e:
print (e)
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()
您的代码包含一些语法和语义错误:
true
应该以大写字母True
开头。在try
bloc中使用raise
,您创建了一个自定义异常,该异常将始终被执行,并且永远不会到达{在
except
关键字之后,有两个选项:except ValueError: print("Non-numeric data found in the file.")
键入代码的正确方法是:
希望有帮助!在
几个错误
您在
if statement
的末尾缺少一个冒号。另外,else
不应该是indented
。最后,我更正了您的try except
语句,因为您无缘无故地提出了ValueError
。所以现在,如果输入不能成功地转换为ints
,那么ValueError
将被引发,loop
将继续(如果没有错误,则代码将继续,并且break
退出循环)。在所以最后的代码是:
我想这就是你想要的:
相关问题 更多 >
编程相关推荐