Sals-shipping

It did let me pass with this code… however, I am aware my code does not clock the potential affordability of drone over ground… how might i have done that? … without functions… i realize that’s coming, and doable much easier with them, but… from here… with the assumed skill set… how would i make this code able to…

“facilitate”(?)

… with more …

“precision”(?)

weight = 119
price_per_pound = 0
price_flat = 20.00
premium_ground = 125.00
total_cost = 0
price_shipping = 0
method = "ground"
# Ground Shipping

print("Ground Shipping Premium $", premium_ground)

# LBS 0 - 2

if (method == "ground") or (method == "premium ground") and (weight > 0) and (weight >= 2):
  price_per_pound = 1.50
  
  if method == "ground":
    price_shipping = price_per_pound * weight
    total_cost = price_shipping + price_flat
    if total_cost < premium_ground: 
      print(total_cost)
    else:
      print("Optimal Option: Premium Ground" , premium_ground)
  elif method == "premium ground":
    
    total_cost = premium_ground
    print(total_cost)

# LBS 2 - 6

elif (method == "ground") or (method == "premium ground") and(weight > 2) and (weight >= 6):
  price_per_pound =  3
  
  if method == "ground":
    price_shipping = price_per_pound * weight
    total_cost = price_shipping + price_flat
    if total_cost < premium_ground: 
      print(total_cost)
    else:
      print("Optimal Option: Premium Ground", premium_ground)

  elif method ==  "premium ground":
    total_cost = price_shipping + premium_ground
    print(total_cost)

# LBS 6 - 10


elif (method == "ground") or (method == "premium ground") and (weight > 6) and (weight >= 10):
  price_per_pound = 4
  
  
  if method == "ground":
    price_shipping = weight * price_per_pound
    total_cost = price_shipping + price_flat
    if total_cost < premium_ground: 
      print(total_cost)
    else:
      print("Optimal Option: Premium Ground", premium_ground)  
  
  elif method == "premium ground":
    total_cost = premium_ground
    print(total_cost)


# LBS 10+
elif (method == "ground") or (method == "premium ground") and (weight > 10):
  price_per_pound += 4.75
  
  
  if method == "ground":
    price_shipping = weight * price_per_pound
    total_cost = price_shipping + price_flat
    if total_cost < premium_ground: 
      print(total_cost)
    else:
      print("Optimal Option: Premium Ground", premium_ground)
  
  elif method == "premium ground":
    total_cost =  premium_ground
    print(total_cost)







#Drone Shipping
if (method == "drone") and (weight > 0) and (weight >= 2):
  price_per_pound = 4.50
  price_shipping = price_per_pound * weight
  print(price_shipping)
  
elif(method == "drone") and (weight > 2) and (weight >= 6):
  price_per_pound =  9
  price_shipping = price_per_pound * weight
  print(price_shipping)



elif(method == "drone") and (weight > 6) and (weight >= 10):
  price_per_pound = 12
  price_shipping = price_per_pound * weight
  print(price_shipping)

elif(method == "drone") and (weight > 10):
  price_per_pound += 14.25
  price_shipping = price_per_pound * weight
  print(price_shipping)

I’m not too sure exactly what you mean by facilitate with more precision, but a look at your code suggests the variables stated above will never satisfy the conditions you’ve set.

This is due to the fact that the variable “method”, containing the character string “ground” never gets changed to “drone” which is what your set of if(AND AND AND) conditions are looking for.

If you put the code…

method = “drone”

between lines 82 and 89, you’ll enable the if statements to trigger at the very least

I hope this helps, this is my first post on the forum.

no i understand that… the method variable doesnt support state changing but if i set the method to ground it will still compare grounds price to ground_premium
and print the better of two options
but it wont compare to drone

and if i set the variable method to drone
it WONT compare against ground prices before printing

One issue might be that you have set a number of global variables.
If I’m not mistaken, the directions ask one to write a series of functions (normal_ground() and print_best_ship or something like that) with different weight parameters so that any weight can be passed as an argument through the function and the appropriate shipping option will be shown as the result.

Take a look around the forums for some hints as to how to go about this project, as this is a heavily posted about topic.

no the instructions originally were pre function in the syllabus… as i stated in the beginning

how might i have done that? … without functions… i realize that’s coming, and doable much easier > with them, but…

im taking the current syllabus… functions are not taught yet… the link is in the original post…i wanna grab these fundamentals and the syllabus believes it can be done w/o functions :slight_smile: :slight_smile: :100:

any ideas :question: :no_mouth: :pleading_face: :pray:

weight = 119
price_flat = 20.00
premium_ground = 125.00

Determine Ground Shipping Cost

if weight <= 2:
price_per_pound_ground = 1.50
elif weight <= 6:
price_per_pound_ground = 3.00
elif weight <= 10:
price_per_pound_ground = 4.00
else:
price_per_pound_ground = 4.75

ground_cost = price_flat + (price_per_pound_ground * weight)

Determine Drone Shipping Cost

if weight <= 2:
price_per_pound_drone = 4.50
elif weight <= 6:
price_per_pound_drone = 9.00
elif weight <= 10:
price_per_pound_drone = 12.00
else:
price_per_pound_drone = 14.25

drone_cost = price_per_pound_drone * weight

Compare Costs for Best Option

print(“Ground Shipping Cost: $”, ground_cost)
print(“Premium Ground Shipping Cost: $”, premium_ground)
print(“Drone Shipping Cost: $”, drone_cost)

if ground_cost < drone_cost and ground_cost < premium_ground:
print(“Best Option: Regular Ground $”, ground_cost)
elif drone_cost < ground_cost and drone_cost < premium_ground:
print(“Best Option: Drone $”, drone_cost)
else:
print(“Best Option: Premium Ground $”, premium_ground)

I wont take credit for this answer - but it does work pretty lovely-like

take credit if its your work…

and yes it does my fellow dreamer :100: :100:

also THANK YOUUU!!!
:bowing_man: :bowing_man:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.