Https://www.codecademy.com/courses/learn-python-3/projects/sals-shipping

When I run my code, I get one error
File “script.py”, line 32
ground_shipping(2)
^
SyntaxError: invalid syntax

My code:

def ground_shipping(weight):
  if (weight > 10): 
    ground_shipping == (weight * 4.75) + 20 
  elif (weight > 6 and weight <= 10): 
    ground_shipping == (weight * 4) + 20 
  elif (weight > 2 and weight <= 6): 
    ground_shipping == (weight * 3) + 20 
  else: 
    ground_shipping == (weight * 1.5) + 20

def drone_shipping_cost(weight): 
  if (weight > 10):
    drone_shipping_cost == weight * 14.25 
  elif (weight > 6 and weight <= 10): 
    drone_shipping_cost == weight * 12
  elif (weight > 2 and weight <= 6): 
    drone_shipping_cost == weight * 9
  else: 
    drone_shipping_cost == weight * 4.50

def premimum_ground_shipping(weight): 
  premimum_ground_shipping = weight + 125

def cheapest(weight):  
  if (ground_shipping(weight) < premimum_ground_shipping(weight) and ground_shipping(weight) < drone_shipping_cost(weight)): 
    print("Ground shpping is the cheapest. Ground shipping cost " + str(ground_shipping)) 
  elif (premimum_ground_shipping(weight) < ground_shipping(weight) and premimum_ground_sipping(weight) < drone_shipping_cost(weight)):
    print("Prenium ground shipping is the cheapest. Prenimum ground shipping cost " + str(premimum_ground_shipping(weight))) 
  else: 
    print("Drone shipping is cheapest. Drone shipping shipping cost " + str(drone_shipping_cost(weight))

ground_shipping(2)
drone_shipping_cost(9)
premimum_ground_shipping(5)
cheapest(17)

type or paste code here

With errors, always check the line above as well:

print("Drone shipping is cheapest. Drone shipping shipping cost " + str(drone_shipping_cost(weight))

parentheses allow us to put code on multiple lines, forgetting to close the parentheses can as a result give strange errors.

2 Likes

Traceback (most recent call last):
File “script.py”, line 35, in
cheapest(17)
File “script.py”, line 25, in cheapest
if (ground_shipping(weight) < premimum_ground_shipping(weight) and ground_shipping(weight) < drone_shipping_cost(weight)):
TypeError: ‘<’ not supported between instances of ‘NoneType’ and ‘NoneType’

`def cheapest(weight):  
  if (ground_shipping(weight) < premimum_ground_shipping(weight) and ground_shipping(weight) < drone_shipping_cost(weight)): 
    print("Ground shpping is the cheapest. Ground shipping cost " + str(ground_shipping)) 
  elif (premimum_ground_shipping(weight) < ground_shipping(weight) and premimum_ground_sipping(weight) < drone_shipping_cost(weight)):
    print("Prenium ground shipping is the cheapest. Prenimum ground shipping cost " + str(premimum_ground_shipping(weight))) 
  else: 
    print("Drone shipping is cheapest. Drone shipping shipping cost " + str(drone_shipping_cost(weight))) 

ground_shipping(2)
drone_shipping_cost(9)
premimum_ground_shipping(5)
cheapest(17)`

you barely got this new error? Have you tried debugging the problem? you could start by insert a print() before the error line, to see what variable is None, and work your way up from there

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.