Sal's Shipping Syntax Error

In Sal’s Shipping, I keep on getting a syntax error with the final function
https://www.codecademy.com/courses/learn-python-3/projects/sals-shipping

def cheapest(weight):
  G = ground_shipping(weight)
  D = drone_shipping(weight)
  if G < D and G < premium_ground_shipping:
    return(print("The cheapest shipping method is ground shipping, it will cost $" + str(G))
  elif D < G and D < premium_ground_shipping:
    return(print("The cheapest shipping method is drone shipping, it will cost $" + str(D)))
  else:
    return(print("The cheapest shipping method is premium shipping, it will cost $" + str(P)))

cheapest(10)

The Syntax error says the elif line is wrong, but I don’t understand how the if line is correct but the elif line isn’t.

return is not a function so does not need parenthesis. They are ignored when present but still need to be paired. The line above the one indicated by the error is missing a closing paren.

Thankyou. I haven’t come across how to use return and print together correctly until now. I can now see that by using more brackets than was necessary, I lost track of the pairing. I removed the excess parentheses and the code worked. Thanks again :slight_smile:

2 Likes

We generally don’t return and print at the same time. If there is no need for the return, then just print, otherwise, return and then print at the caller.

1 Like