Sal's Shipping output - None

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

I have completed the project however for the two test statements I get an output of none for one of them and I don’t know why. Link to task:

def cost_g_shipping(weight): 
  if (weight <= 2):
    price_pound = 1.50
  elif weight <= 6:
    price_per_pound = 3.00
  elif weight <= 10:
    price_per_pound = 4.00
    price_per_pound = 4.75
  return 20 + (price_per_pound * weight)

shipping_cost_premium = 125.00

def cost_d_shipping(weight): 
  if (weight <= 2):
    price_per_pound = 4.50
  elif weight <= 6:
    price_per_pound = 9.00
  elif weight <= 10:
    price_per_pound = 12.00
    price_per_pound = 14.25
  return price_per_pound * weight

def cheapest_method(weight):
  ground_cost = cost_g_shipping(weight)
  premium_cost = shipping_cost_premium
  drone_cost = cost_d_shipping(weight)
  if (ground_cost < premium_cost) and (ground_cost < drone_cost):
    method = 'Standard Ground'
    cost = ground_cost
  elif (drone_cost<ground_cost) and (drone_cost<premium_cost):
    method = 'Drone'
    cost = drone_cost
    method = 'Premium'
    cost = premium_cost
    print('The cheapest shipping method for you is $%.2f with %s Shipping.'
    %(cost, method))

For the input of 4.8lbs it prints ‘None’, it should print $34.40. Where did I go wrong?

1 Like

Hi @immortaldarknorth - welcome to the forum.

Take a look at the indentation level of your print call:

    print('The cheapest shipping method for you is $%.2f with %s Shipping.'
    %(cost, method))

When is that code going to be run, and how is that going to affect the output of your function in each of the various cases in your if-else structure? :slight_smile: