Pls help i M facingf syntax ERROR

def cost_ground(weight):

  if (weight <= 2):

   cost = weight * 1.50 + 20

  elif (weight > 2) and (weight <= 6):

    cost = weight * 3.00 + 20

  elif (weight > 6) and (weight <= 10 ):

    cost =  weight * 4.00 + 20

  else:

    cost = weight * 4.75 + 20

  return cost

    

print(cost_ground(8.40))

premium_ground_shipping = 125.00

def cost_drone(weight):

  if (weight <= 2):

   cost2 = weight * 4.50 

  elif (weight > 2) and (weight <= 6):

    cost2 = weight * 9.00 

  elif (weight > 6) and (weight <= 10 ):

    cost2 =  weight * 12.00 

  else:

    cost2 = weight * 14.25 

  return cost2

print(cost_drone(1.5))

def low_cost(weight):

  if cost_drone(weight) > 125 and cost_ground(weight) > 125:

     print("premium ground is cheapest option"+" "+ str(125))

     low = 125

  elif cost_drone(weight) > cost_ground(weight):

      print("Cost_ground is less" + cost_ground(weight))

      low = cost_ground(weight)

  elif cost_drone(weight) < cost_ground(weight):

      print("Cost_drone is less" + " " +(cost_drone(weight))

      low = cost_drone(weight)

  return low

When the syntax error is at the beginning of the line, always check the line above:

print("Cost_drone is less" + " " +(cost_drone(weight))

parentheses are great, but they also allow you to put code over multiple lines, sometimes leading to slightly confusing syntax error. But once you aware of this, you will be able to debug this kind of errors more quickly.

2 Likes

can u pls explain? I didn’t get u

you forgot to close your print( call.