Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update shipping.py with a few comments #134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 36 additions & 35 deletions 2-control-flow/sals-shipping/shipping.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
# Sal's Shipping
# Sonny Li

weight = 80

# Ground Shipping 🚚

if weight <= 2:
cost_ground = weight * 1.5 + 20
elif weight <= 6:
cost_ground = weight * 3.00 + 20
elif weight <= 10:
cost_ground = weight * 4.00 + 20
else:
cost_ground = weight * 4.75 + 20

print("Ground Shipping $", cost_ground)

# Ground Shipping Premimum 🚚💨

cost_ground_premium = 125.00

print("Ground Shipping Premimium $", cost_ground_premium)

# Drone Shipping 🛸

if weight <= 2:
cost_drone = weight * 4.5
elif weight <= 6:
cost_drone = weight * 9.00
elif weight <= 10:
cost_drone = weight * 12.00
weight = 41.5
#ground shipping
if(weight<2):
g_price = weight * 1.50 + 20.00
print("Ground shipping price is : " + str(g_price))
elif(weight>2 and weight <= 6):
Copy link

@md-coops md-coops Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to check weight > 2 here as the conditional statement would terminate at the if(weight<2) step. This is why we use elif instead of a new independent if statement. With elif we don't need to re-evaluate the previous condition.

g_price = weight * 3.00 + 20.00
print("Ground shipping price is : " + str(g_price))
elif(weight>6 and weight <= 10):
g_price = weight * 4.00 + 20.00
print("Ground shipping price is : " + str(g_price))
elif(weight>10):
g_price = weight * 4.75 + 20.00
print("Ground shipping price is :" + str(g_price))

#drone shipping

if(weight<2):
d_price = weight * 4.50
print("Drone shipping price is : " +
str(d_price))
elif(weight>2 and weight <= 6):
d_price = weight * 9.00
print("Drone shipping price is : " + str(d_price))
elif(weight>6 and weight <= 10):
d_price = weight * 12.00
print("Drone shipping price is : " + str(d_price))
elif(weight>10):
d_price = weight * 14.25
print("Drone shipping price is : " + str(d_price))

if(g_price < d_price):
print("Ground shipping is cheaper and thus we reccomend you to use this package")
elif(g_price > d_price):
print("Drone shipping is cheaper and thus we reccomend you to use this package")
else:
cost_drone = weight * 14.25

print("Drone Shipping: $", cost_drone)
print("Both are of same price, so you are more than welcomed to choose the package you prefer.")