This question already has an answer here:
Why does the print function return None?
                                
                                    (1个答案)
                                
                        
                                3年前关闭。
            
                    
我对Python相当陌生。我正在生成一个发电机,用于估算面包店制作蛋糕所需要花费的费用。虽然这里有些问题

Batches = print("Batches of Cupcakes:", math.ceil(People * Ingredients / 12))

Labor = print("Hours of labor:", Batches * 1.25)


我收到此错误:

TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

最佳答案

因为print始终返回None。您要将先前的结果保存到变量中:

batches = math.ceil(people * ingredients/12)
labor = batches * 1.25

print("Batches of cupcakes:", batches)
print("Hours of labor:", labor)

关于python - 为什么返回Nonetype? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39802548/

10-09 14:30