I'm trying to write a program that will calculates that prompts the user to enter both the value and weight of an order and displays the shipping cost.
Shipping charges for online orders are based on the value of the order and the shipping weight. 100ドル+ there is no shipping and on orders less than 100ドル shipping charges are as follows: Over 40 lbs: 1ドル.09 per lb. Over 20 lbs: 0ドル.99 per lb. Equal to or Under 20 lbs: 0ドル.89 per lb.
If the order value is 100ドル+ the weight is irrelevant and your program should not ask for it.
So far this is what I have:
#Have user enter weight of order
weight = int(input('Enter the weight of your order:'))
#Determine shipping cost
if weight >= 40:
total = weight * 1.09
elif weight >= 20:
total = weight * 0.99
elif weight <=20:
total = weight * 0.89
#does shipping apply
if total >= 100.00
else:
if total <= 100.00
I'm not to sure where to go from here and what to put in the else string under does shipping apply.
2 Answers 2
You should not use else
, just print
. Or you can use this:
if total >= 100.00:
print()
else:
-
so by putting nothing in the parenthesis it will automatically skip down to the next if? If so, is there a way to ask a question here?mrsga16eats– mrsga16eats2016年05月28日 04:05:53 +00:00Commented May 28, 2016 at 4:05
You should start by checking the value of the order. As you said, if it's over 100,ドル then weight isn't important because it's free shipping anyway. You probably already have that number from elsewhere in your program, so just check the value. Then you can move on to checking weight if necessary.
# value is defined earlier in the program, and contains the total cost of the purchase
if value >= 100:
print "You quality for free shipping!"
else:
weight = int(input("Enter the weight of your order: "))
# Now determine shipping cost
if weight > 40:
total = weight * 1.09
elif weight > 20:
total = weight * 0.99
else: # because there should only be weights equal to or below 20 remaining
total = weight * 0.89
Now you can present the user with a total, or do any other things you want.