我正在尝试将下面的语句翻译成Python,但却遇到了重新出错的错误。
hours = input (prompt1)
^
IndentationError: expected an indented block
当每周工作40小时时,工人获得小时工资。当工作时间在一周内超过40小时时,工人的加班费率是小时工资的1.5倍。考虑到每周工作的小时数和小时工资,计算工人的每周工资。
prompt1 = 'How many hours did you work?\n'
try:
hours = input (prompt1)
prompt2 = 'What is your hourly rate?\n'
rate = input (prompt2)
hours = float(hours)
rate = float(rate)
print float(hours) * float(rate*1.5)
except:
print('Error, Please enter a number')
我非常感谢你的帮助。
答案 0 :(得分:0)
在Python中,没有{}
或begin
+ end
使用标识。您的代码应如下所示:
prompt1 = 'How many hours did you work?\n'
try:
hours = input (prompt1)
prompt2 = 'What is your hourly rate?\n'
rate = input (prompt2)
hours = float(hours)
rate = float(rate)
if(hours > 40):
rate = rate * 1.5
print float(hours) * float(rate*1.5)
except:
print('Error, Please enter a number')