Python—引用新函数中定义的函数

Python—引用新函数中定义的函数,python,Python,我正在自学Python,在一个练习中定义了3个函数(c_ground_shipping,prem_ground_shipping,和drone_shipping),每个函数都返回一个整数,表示交付特定重量包裹的不同运输方法的成本 我现在试图定义一个新函数,它将返回最便宜的运输方法 我写了以下内容: def cheap_shipping(weight): if c_ground_shipping < prem_ground_shipping and c_ground_shipping &

我正在自学Python,在一个练习中定义了3个函数(
c_ground_shipping
prem_ground_shipping
,和
drone_shipping
),每个函数都返回一个整数,表示交付特定重量包裹的不同运输方法的成本

我现在试图定义一个新函数,它将返回最便宜的运输方法

我写了以下内容:

def cheap_shipping(weight):
  if c_ground_shipping < prem_ground_shipping and c_ground_shipping < drone_shipping:
    return "The cheapest shipping method for your package is Ground Shipping. This will cost you £" + str(c_ground_shipping) + " to ship."
  elif prem_ground_shipping < drone_shipping:
    return "The cheapest shipping method for your package is Premium Ground Shipping. This will cost you £" + str(prem_ground_shipping) + " to ship."
  else:
    return "The cheapest shipping method for your package is Drone Shipping. 
This will cost you £" + str(drone_shipping) + " to ship."

print (cheap_shipping(4.8))

我认为问题在于,您正在尝试比较函数,而不是函数返回的结果。例如

if c_ground_shipping < prem_ground_shipping and c_ground_shipping < drone_shipping:
如果c_地面运输
应该是:

if c_ground_shipping(weight) < prem_ground_shipping(weight) and c_ground_shipping(weight) < drone_shipping(weight):
如果c_地面运输(重量)
谢谢,但我也试过了,也没用。我认为这可能不像我当时称之为“打印(廉价运输(4.8))”时那样有效,我只是定义了廉价运输的重量。如果所有函数都使用变量权重,则不确定这是否相关。是同一个错误:TypeError:unorderable types:function()if c_ground_shipping < prem_ground_shipping and c_ground_shipping < drone_shipping:
if c_ground_shipping(weight) < prem_ground_shipping(weight) and c_ground_shipping(weight) < drone_shipping(weight):