Python 3: Can you refer to a previous function from inside a new function?

I’m doing the Sal’s Shipping exercise and I’m having difficulty understanding why I cannot seem to refer to a previously defined function (stand_ground_ship) when defining my new function (drone_ship). I’ve included my code for reference.

Shouldn’t I be able to just multiply stand_ground_ship by 3 and remove the $20 flat fee?

def stand_ground_ship(weight):
  if weight <= 2:
    price_per_lb = 1.50
  elif weight <= 6:
    price_per_lb = 3.00
  elif weight <= 10:
    price_per_lb = 4.00
  else:
    price_per_lb = 4.75
  
  return 20 + (price_per_lb * weight)

prem_ground_ship = 125.00

#Drone shipping has no flat charge, but the rate based on weight is triple the rate of ground shipping
def drone_ship(weight):
  return 20 - (stand_ground_ship * 3)

print(drone_ship(1.5))

you want to multiply a function by three? what would the result of that be? three functions?

I want to multiply the result of the function by 3. They are both using the same variable (weight). Maybe I’m thinking about this all wrong

If you have a function and want something else, what would you need to do get that other thing?

Don’t write something and expect it to work, rather, look at what you have, what you need, think about what goes in-between to bridge that, insert it, observe the result, continue with the next thing.

I could always just define drone_ship by copy/pasting the logic created under stand_ground_ship, and edit each line accordingly. And I understand that’s probably what the lesson wants.

I just didn’t know if there was a way to shortcut this and avoid having to edit each line of logic. I would imagine doing that on larger functions would be quite time consuming. No?

But, maybe I’m trying to run before I can crawl

Does multiplying a function by a number make sense?
Usually you’d multiply two numbers, try that instead.

You said it yourself, you want to multiply the result of your function by 3. A function is not its own result, a function and its result are two different things.

1 Like