I'm working on a little program where the user inputs a price and then the program would output the shipping cost based on the input.
#Initilaize variables
lowUS = 6.00;
medUS = 9.00;
highUS = 12.00;
lowCan = 8.00;
medCan = 12.00;
highCan = 15.00;
#Greet user and ask for input
print("Welcome to Ben's shipping calculator!");
print("We will calculate your shipping cost for you!");
orderTotal = float(input("Please input your total amount."));
country = input("In which country do you reside? Please type C for Canada or U or USA. ");
#Validate input
while country not in {'u', 'c', 'C', 'U'}:
print ("Invalid input. Please try again. ")
country = input("In which country do you reside? Please type C for Canada or U or USA. ");
#Determine how much the shipping fee is
if country == 'U' or country == 'u':
if orderTotal <= 50.00:
if orderTotal > 50.00 and orderTotal <= 100.00:
if orderTotal > 100.00 and orderTotal <= 150.00:
if orderTotal > 150.00:
print("Your shipping is free and your grand total is", orderTotal)
else:
print("Your shipping fee is: ", highUS);
orderTotal = (orderTotal + highUS);
else:
print("Your shipping fee is: ", medUS);
orderTotal = (orderTotal + medUS);
else:
print("Your shipping fee is: ", lowUS);
orderTotal = (orderTotal + lowUS);
elif country == 'c' or country == 'C':
if orderTotal <= 50.00:
if orderTotal > 50.00 and orderTotal <= 100.00:
if orderTotal > 100.00 and orderTotal <= 150.00:
if orderTotal > 150.00:
print("Your shipping is free and your grand total is", orderTotal)
else:
print("Your shipping fee is: ", highCan);
orderTotal = (orderTotal + highCan);
else:
print("Your shipping fee is: ", medCan);
orderTotal = (orderTotal + medCan);
else:
print("Your shipping fee is: ", lowCan);
orderTotal = (orderTotal + lowCan);
print("Your grand total is: $", orderTotal);
I am very new to python and programming and I'm not sure if this is a good way to go at it, but I'm learning if-else statements so I thought I would give it a try. So far it only works if you input "50" for the amount. It will calculate based off of the country only for "50". I'm not sure where I went wrong, if someone could help and explain, that would be great.
ifonly enters if it's less than or equal to 50... the next check you make is if it's greater than 50 which it can't be - so that block will never execute... So yourelseclause is the only one that can execute...