<p>您的代码包含一些语法和语义错误:</p>
<ol>
<li>布尔值<code>true</code>应该以大写字母<code>True</code>开头。在</li>
<li>编写代码的方式非常重要,并且应该以正确的方式进行格式化,每个指令前的空格是敏感的,即同一块代码的前面应该有相同数量的空格。在</li>
<li>通过在<code>try</code>bloc中使用<code>raise</code>,您创建了一个自定义异常,该异常将始终被执行,并且永远不会到达{<cd5>}bloc。在</li>
<li><p>在<code>except</code>关键字之后,有两个选项:</p>
<ul>
<li>输入异常名称,例如:</li>
</ul>
<p><code>except ValueError:
print("Non-numeric data found in the file.")</code></p>
<ul>
<li>或者不指定异常,让它空白</li>
</ul></li>
</ol>
<p>键入代码的正确方法是:<br/></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)
#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()
</code></pre>
<p>希望有帮助!在</p>