Sal's Shipping

Need help, new to programming. I keep getting
File “script.py”, line 46
print(cheapest_shipping(4.8))
^
SyntaxError: invalid syntax

Here’s my code

def ground_shipping(weight):

if weight <= 2:

price_per_pound = 1.50

elif weight <= 6:

price_per_pound = 3.00

elif weight <= 10:

price_per_pound = 4.00

elif weight > 10:

price_per_pound = 4.75

return (weight * price_per_pound + 20)

print(ground_shipping(8.4))

premium_shipping = 125

def drone_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

elif weight > 10:

price_per_pound = 14.25

return (weight * price_per_pound + 0)

print(drone_shipping(1.5))

def cheapest_shipping(weight):

premium = premium_shipping

ground = ground_shipping(weight)

drone = drone_shipping(weight)

if ground < premium and ground < drone:

method = "Ground Shipping"

cost = ground

elif drone < premium and drone < ground:

method = "Drone Shipping"

cost = drone

else:

method = "Premium Shipping"

cost = premium

print(“The cheapest option available is $%.2f with %s shipping.” % (cost, method)

print(cheapest_shipping(4.8))

print(cheapest_shipping(41.5))

Hey there @py5836685587 and welcome to the Codecademy forums!! :slightly_smiling_face:

Often times if a SyntaxError appears and your certain the error is not on the line being pointed to, you can take a look at the line before.

Hint if needed

Try comparing things like the number of opening brackets to the number of closing brackets.


On a side note, please look at properly formatting you code in the future. It looks like you attempted here but didn’t quiet get it.

Simply press this button:

Than copy/paste all of your code in between the two rows of backticks:

1 Like
def ground_shipping(weight):
  if weight <= 2:
    price_per_pound = 1.50
  elif weight <= 6:
    price_per_pound = 3.00
  elif weight <= 10:
    price_per_pound = 4.00
  elif weight > 10:
    price_per_pound = 4.75
  return (weight * price_per_pound + 20)

print(ground_shipping(8.4))

premium_shipping = 125

def drone_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
  elif weight > 10:
    price_per_pound = 14.25
  return (weight * price_per_pound + 0)

print(drone_shipping(1.5))


def cheapest_shipping(weight):
  premium = premium_shipping
  ground = ground_shipping(weight)
  drone = drone_shipping(weight)
  
  if ground < premium and ground < drone:
    method = "Ground Shipping"
    cost = ground
  elif drone < premium and drone < ground:
    method = "Drone Shipping"
    cost = drone
  else:
    method = "Premium Shipping"
    cost = premium
print("The cheapest option available is $%.2f with %s shipping." % (cost, method)

print(cheapest_shipping(4.8))
print(cheapest_shipping(41.5))```

Sorry if I’m a little slow, but I double-checked everything, and I checked the walkthrough video to make sure everything was correct but I still get the same error.

Double check your indentation in your last function definition.

You mean the def cheapest_shipping(weight):

Yes. look at the print statement and the use of parenthesis as well.

I honestly don’t see the problem, all the print statements that contain the function are the same, they have the same parenthesis and have no indention.

The first two work

EUREKA !!!, the only problem now is that it prints none

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

print(ground_shipping(8.4))

premium_shipping = 125

def drone_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
  elif weight > 10:
    price_per_pound = 14.25
  return (weight * price_per_pound + 0)

print(drone_shipping(1.5))


def cheapest_shipping(weight):
  premium = premium_shipping
  ground = ground_shipping(weight)
  drone = drone_shipping(weight)
  
  if ground < premium and ground < drone:
    method = "Ground Shipping"
    cost = ground
  elif drone < premium and drone < ground:
    method = "Drone Shipping"
    cost = drone
  else:
    method = "Premium Shipping"
    cost = premium
  print("The cheapest option available is " +str(cost)+ " with " +method)
  
print(cheapest_shipping(4.8))
print(cheapest_shipping(41.5))

I would like to thank you guys and everybody’s posts I looked at for help.

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

print(ground_shipping(8.4))

premium_shipping = 125

def drone_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
  elif weight > 10:
    price_per_pound = 14.25
  return (weight * price_per_pound + 0)

print(drone_shipping(1.5))


def cheapest_shipping(weight):
  premium = premium_shipping
  ground = ground_shipping(weight)
  drone = drone_shipping(weight)
  
  if ground < premium and ground < drone:
    method = "Ground Shipping"
    cost = ground
  elif drone < premium and drone < ground:
    method = "Drone Shipping"
    cost = drone
  else:
    method = "Premium Shipping"
    cost = premium
  return "The cheapest option available is " +str(cost)+ " with " +method
  
print(cheapest_shipping(4.8))
print(cheapest_shipping(41.5))```
2 Likes