乘浮点数(Python 3.7)

乘浮点数(Python 3.7),python,Python,这可能是一个非常简单的问题,但现在是凌晨2点,我的大脑在试图找出它们为什么不能一起繁殖: Prate2 = float(input("Please input the hourly rate of the plumber you would like to calculate: \n")) Pfee2 = float(input("Please input the callout fee of the plumber you would like to calcul

这可能是一个非常简单的问题,但现在是凌晨2点,我的大脑在试图找出它们为什么不能一起繁殖:

Prate2 = float(input("Please input the hourly rate of the plumber you would like to calculate: \n"))
Pfee2 = float(input("Please input the callout fee of the plumber you would like to calculate: \n"))
multiply = float(amountHours * Prate2)
total = (multiply) + (Pfee2)
print("The total cost of service:" ,(multiply) , "With a callout fee of",(Pfee2) , "to give a total of:", total)
它给我一个TypeError的错误消息:不能将序列乘以'float'类型的非int


任何帮助都将不胜感激,谢谢

您的amountHours类型可能是字符串。您想要的可能是这样的:

multiply = float(amountHours) * Prate2
上面的行cast amountHours为float,然后cast的结果与Prate2相乘,Prate2也是一个float


您的原始代码首先应用乘法,这会导致错误。

未定义amountHours可能是未在您发布的代码中定义的amountHours是某种序列。如果amountHours是序列,例如列表、元组、字符串,则会导致错误。如错误所述,不能将序列与浮点相乘。但是,您可以乘以integer@jakub但是将一个列表乘以一个整数可能不会得到运算的结果wants@PaulH-是的,我只是想知道这是可能的