擅长:python、mysql、java
<h2>几个错误</h2>
<p>您在<code>if statement</code>的末尾缺少一个冒号。另外,<code>else</code>不应该是<code>indented</code>。最后,我更正了您的<code>try except</code>语句,因为您无缘无故地提出了<code>ValueError</code>。所以现在,如果输入不能成功地转换为<code>ints</code>,那么<code>ValueError</code>将被引发,<code>loop</code>将继续(如果没有错误,则代码将继续,并且<code>break</code>退出循环)。在</p>
<p>所以最后的代码是:</p>
<pre><code>while True:
hrs = input ("Enter no.of hrs worked: ")
rate = input ("Enter the rate per hour: ")
try:
hrs = int(hrs)
rate = int(rate)
break
except ValueError:
print("invalid entries")
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)
</code></pre>