Sal Shipping - Syntax error

Hello, This is from the project of Python - Function and logic, Python control flow. I’m getting syntax error in this code at the function cheapest_way_calculator(weight) by don’t know what I’m doing wrong. Please guide me.

def ground(weight):
  if weight <= 0:
    return "invalid weight."
  elif weight <= 2:
    return (1.50*weight)+20.00
  elif weight <=6:
    return (3.00*weight)+20.00
  elif weight <=10:
    return (4.00*weight)+20.00
  else:
    return (4.75*weight)+20.00

print (ground(8.4))

premium = 125.00

def drone (weight):
  if weight <= 0:
    return "invalid weight."
  elif weight <= 2:
    return(4.50*weight)
  elif weight <=6:
    return(9.00*weight)
  elif weight <=10:
    return(12.00*weight)
  else:
    return(14.25*weight)

print(drone(1.5))

def cheapest_way_calculator(weight):
  if ground(weight)<drone(weight) and ground(weight)<premium:
    print("The cheapest Shipping method is Ground shipping. It Costs $"ground(weight)".")
  elif drone(weight)<ground(weight) and drone(weight)<premium:
    print("The cheapest Shipping method is Drone Shipping. It Costs $"drone(weight)".")
  else:
    print("The cheapest Shipping method is Premium Ground Shipping. It Costs $"premium".")

print(cheapest_way_calculator(4.8))

Doesn’t the error message help? It tells you that the way you try to insert the function call in the string is not a valid way

how can we insert variables/function calls in a string?

I tried adding str() but it didn’t help. also, tried changing that function into variable.

str() would indeed convert the float to a string. But that doesn’t explain how you glue it together.

Its okay to consult documentation or earlier lessons if you need a refresher on string concatenation or printing strings with variables.

I checked the video and saw that something like %.2f & %s is used. but I don’t remember learning something like that in previous classes. so, Is it me or is it not there?

I used + and it worked but now it prints like this,

The cheapest Shipping method is Premium Ground Shipping. It Costs $125.0.
None

What is this none?

using .format() is a viable option. + would also work, but I would recommend using .format(). You can take some time to learn that.

the function doesn’t return anything, yet when you call the function you print the returned result

1 Like

Thank you. I don’t think it was in previous lessons but I learnt it here :grinning: o, thank you so much.