cjxsam
1
Could anyone please help me with step 2 on Sal’s Shipping Please
Code: weight = 3 #"Ground Shipping" if weight <= 3: cost_ground = weight * 1.5 + 20 elif weight >= 6: cost_ground = weight * 3 + 20 elif weight >= 10: cost_ground = weight * 4 + 20 else: weight > 10: cost_ground = weight * 4.75 + 20
Link: https://www.codecademy.com/courses/learn-python-3/projects/python-sals-shipping
cjxsam
2
Code:
weight = 3
#"Ground Shipping"
if weight <= 3:
cost_ground = weight * 1.5 + 20
elif weight >= 6:
cost_ground = weight * 3 + 20
elif weight >= 10:
cost_ground = weight * 4 + 20
else:
weight > 10:
cost_ground = weight * 4.75 + 20
Did you try what I suggested here?
After each if
you should be using return
to return a cost/value. The instructions say to use print()
, which you’ve not done.
Also, your else
should cover everything else over the weight of 10 (not including 10).
ex:
else:
cost_ground = weight * 4.75 + 20
print(cost_ground)
change the weight
variable and see what happens with the code.
weight = 111
#"Ground Shipping"
if weight <= 3:
cost_ground = weight * 1.5 + 20
elif weight >= 6:
cost_ground = weight * 3 + 20
elif weight >= 10:
cost_ground = weight * 4 + 20
else:
cost_ground = weight * 4.75 + 20
print(cost_ground)
Make sure that you are at least printing the result after the expression…
if weight <= 2:
cost_ground = weight * 1.5 + 20
print(cost_ground)
# or
return cost_ground
cjxsam
5
yes i have got it now thank you everyone