My Sal's Shipping challenge on Codecademy This is my attempt on the Python 3 Sal's Shipping challenge on Codecademy (Challenge Link (instructions in the link)).

I'd really appreciate anyone to take the time to review my code. I'm a very new to programming and I really wanna improve my coding, so all feedback is apreciated.

def groundCost(weight):
  if weight &gt; 10:
    cost = weight * 4.75
  elif weight &gt; 6:
    cost = weight * 4
  elif weight &gt; 2:
    cost = weight * 3
  else:
    cost = weight * 1.5
  cost += 20
  return cost

def droneCost(weight):
  if weight &gt; 10:
    cost = weight * 14.25
  elif weight &gt; 6:
    cost = weight * 12
  elif weight &gt; 2:
    cost = weight * 9
  else:
    cost = weight * 4.5
  return cost

def costCalc(weight):
  g = groundCost(weight)
  p = 125
  d = droneCost(weight)
  gS = "Ground Shipping"
  pS = "Premium Ground Shipping"
  dS = "Drone Shipping"
  if d == g or d == p or g == p:
    if d == g and d == p:
      print("All shipping methods cost $125 according to your items weight")
      return 
    if d == g:
      same1 = dS
      same2 = gS
      cost = d
    if d == p:
      same1 = dS
      same2 = pS
      cost = d
    if g == p:
      same1 = gS
      same2 = pS
      cost = g
    print("Youre cheapest shipping method is "+same1+" and "+same2+" as they both cost $"+str(cost))
    return
  elif (g &lt; d) and g &lt; p:
    cheapMeth = gS
    cost = g
  elif (p &lt; d) and p &lt; g:
    cheapMeth = pS
    cost = p
  elif (d &lt; g) and d &lt; p:
    cheapMeth = dS
    cost = d
  print("Youre cheapest shipping method is "+cheapMeth+" costing $"+str(cost))
  return
weight = int(input())
costCalc(weight)
Ok, first of all you should've take care of variable names. Naming them like p, g, e, etc is really a bad habbit. 

Once you change them, it's much easier to read.

def cost_calc(weight):
  ground_cost = calculate_ground_cost(weight)
  drone_cost = calculate_drone_cost(weight)
  premium_cost = 125
  ground_shipping_name = "Ground Shipping"
  premium_shipping_name = "Premium Ground Shipping"
  drone_shipping_name = "Drone Shipping"


Second python naming convention tells you to use underscores while naming variables or functions.

Third, your functionc that calculates costs can be minimized in many ways, when one of them is:

import bisect 

def calculate_ground_cost(weight):
  limits = [2, 6, 10]
  multipliers = [1.5, 3, 4, 4.75]
  idx = bisect.bisect_left(limits, weight)
  return (weight * multipliers[idx]) + 20

def calculate_drone_cost(weight):
  limits = [2, 6, 10]
  multipliers = [4.5, 9, 12, 14.25]
  idx = bisect.bisect_left(limits, weight)
  return (weight * multipliers[idx])


Then you should take care of IFs statements that are really messy.

if drone_cost == ground_cost or drone_cost == premium_cost or ground_cost == premium_cost:


Is equvalent to

if drone_cost == ground_cost == premium_cost:


And the next rule good to follow is always return ASAP.

if drone_cost == ground_cost == premium_cost:
    return "All shipping method cost %s according to your items weight" % premium_cost


Then all of this mess:

if  d == g and d == p:
      print("All shipping methods cost $125 according to your items weight")
      return 
    if d == g:
      same1 = dS
      same2 = gS
      cost = d
    if d == p:
      same1 = dS
      same2 = pS
      cost = d
    if g == p:
      same1 = gS
      same2 = pS
      cost = g
    print("Youre cheapest shipping method is "+same1+" and "+same2+" as they both cost $"+str(cost))
    return


Can be changed to

if ground_cost == drone_cost:
    return "Youre cheapest shipping method is %s and %s as they both cost$%s" %(ground_shipping_name, premium_shipping_name, ground_cost)


Because this is the last "IF" that is matching the statement.

And at the end, where u try to determine what is the lowest cost:

  elif (g &lt; d) and g &lt; p:
    cheapMeth = gS
    cost = g
  elif (p &lt; d) and p &lt; g:
    cheapMeth = pS
    cost = p
  elif (d &lt; g) and d &lt; p:
    cheapMeth = dS
    cost = d
  print("Youre cheapest shipping method is "+cheapMeth+" costing $"+str(cost))
  return


You can change it to 

costs = sorted([
   (ground_cost, ground_shipping_name), 
   (drone_cost, drone_shipping_name), 
   (premium_cost, premium_shipping_name)])

min_cost, method = costs[0]
return "Your cheapest shipping method is %s costing $%s" % (method, min_cost)


So at the end, your code look like:

import bisect 

def calculate_ground_cost(weight):
  limits = [2, 6, 10]
  multipliers = [1.5, 3, 4, 4.75]
  idx = bisect.bisect_left(limits, weight)
  return (weight * multipliers[idx]) + 20

def calculate_drone_cost(weight):
  limits = [2, 6, 10]
  multipliers = [4.5, 9, 12, 14.25]
  idx = bisect.bisect_left(limits, weight)
  return (weight * multipliers[idx])

def cost_calc(weight):
  ground_cost = calculate_ground_cost(weight)
  drone_cost = calculate_drone_cost(weight)
  premium_cost = 125
  ground_shipping_name = "Ground Shipping"
  premium_shipping_name = "Premium Ground Shipping"
  drone_shipping_name = "Drone Shipping"
  if drone_cost == ground_cost == premium_cost:
    return "All shipping methodrone_shipping_name cost $125 according to your items weight"

  if ground_cost == drone_cost:
    return "Youre cheapest shipping method is %s and %s as they both cost$%s" %(ground_shipping_name, premium_shipping_name, ground_cost)

  costs = sorted([
    (ground_cost, ground_shipping_name), 
    (drone_cost, drone_shipping_name), 
    (premium_cost, premium_shipping_name)])

  min_cost, method = costs[0]

  return "Your cheapest shipping method is %s costing $%s" % (method, min_cost)


weight = int(input("Enter weight: "))
print(cost_calc(weight))