In this project, https://www.codecademy.com/courses/learn-python-3/projects/python-sals-shipping, I am using round()
function on cost variables so I can round them 2 decimal places. The
Built-in Functions — Python 3.9.7 documentation syntax is round ( number [, ndigits ])
weight = 4.8
# Ground shipping
if weight <= 2:
ground_cost = round(weight * 1.50 + 20.00, 2)
elif weight > 2 and weight <=6:
ground_cost = round(weight * 3.00 + 20.00, 2)
elif weight > 6 and weight <= 10:
ground_cost = round(weight * 4.00 + 20.00, 2)
else:
ground_cost = round(weight * 4.75 + 20.00, 2)
# Ground shipping premium
ground_cost_premium = 125.00
#print('Ground cost premium:',ground_cost_premium)
# Drone shipping
if weight <= 2:
drone_cost = round(weight * 4.50, 2)
elif weight > 2 and weight <=6:
drone_cost = round(weight * 9.00, 2)
elif weight > 6 and weight <= 10:
drone_cost = round(weight * 12.00, 2)
else:
drone_cost = round(weight * 14.25, 2)
print("Ground Shipping:","$", ground_cost)
print("Ground Shipping Premium:","$", ground_cost_premium)
print("Drone Shipping:","$", drone_cost)
print("")
if ground_cost < drone_cost and ground_cost < ground_cost_premium:
print("Ground Shipping is your cheapest option.")
elif drone_cost < ground_cost and drone_cost < ground_cost_premium:
print("Shipping by Drone is your cheapest option.")
else:
print("Premium Ground Shipping is your cheapest option.")
I am expecting this code to round my print statements to the hundredths place, but instead it is rounded to the tenths.
Ground Shipping: $ 34.4
Ground Shipping Premium: $ 125.0
Drone Shipping: $ 43.2
Ground Shipping is your cheapest option.
Can someone help with my syntax please?