在尝试运行以下代码以在同一行上打印浮点数和字符串时,我得到的错误是:"无法转换'浮动'隐含地反对str#34;
hours_worked = float(input ("Enter number of hours worked:"))
hourly_rate = float(input ("Enter hourly rate:"))
compute = hours_worked * hourly_rate
overtime = hours_worked - 40
overtime_rate = 1.5*hourly_rate
Total = overtime * overtime_rate + 40*hourly_rate
if hours_worked <= 40:
print ('You worked' + hours_worked + 'and your pay is' + compute)
else:
print ('You worked' + hours_worked + 'and your pay is' + Total)
答案 0 :(得分:0)
我猜这是Python 3,但因为它没有用我最好的猜测语言标记。
你只需要将hours_worked和compute计算回float类型中的字符串类型,如下所示:
print ('You worked' + str(hours_worked) + 'and your pay is' + str(compute))