Selecting the right else statement depending on user input
<p>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.</p>

<pre><code>#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 &lt;= 50.00:
        if orderTotal &gt; 50.00 and orderTotal &lt;= 100.00:
            if orderTotal &gt; 100.00 and orderTotal &lt;= 150.00:
                if orderTotal &gt; 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 &lt;= 50.00:
        if orderTotal &gt; 50.00 and orderTotal &lt;= 100.00:
            if orderTotal &gt; 100.00 and orderTotal &lt;= 150.00:
                if orderTotal &gt; 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);
</code></pre>

<p>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.</p>

<p>Your first <code>if</code> only 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 your <code>else</code> clause is the only one that can execute... Basically, your nested <code>if</code> statements won't execute because the criteria for doing so is already excluded from the enclosing <code>if</code>.</p>

<p>You're best off restructuring your logic as:</p>

<pre><code>if orderTotal &gt; 150:
    # do something
elif orderTotal &gt; 100:
    # do something
elif orderTotal &gt; 50:
    # do something
else: # 50 or under...
    # do something else
</code></pre>

python variables if-statement