Else statement in Python 3 always runs
<p>I've been making a basic calculator with Python and I have come across this issue. After the calculations are made "Invalid Number" always prints and then the pause happens. I think it has something to do with the newline breaking the <strong>if</strong> block but I'm not sure.</p>

<p>Any help will be appreciated.
Thanks in advance.</p>

<pre><code>def badnum():
        print("Invalid Number")
        print("Press enter to continue")
        input("")
def main():
        print("Select an action ")
        print("1.) Add")
        print("2.) Subtract")
        print("3.) Multiply")
        print("4.) Divide")
        ac = int(input("&gt;&gt;&gt;"))
        if ac == 1:
                print("First number :")
                fn = float(input("&gt;&gt;&gt;"))
                print("Second number :")
                sn = float(input("&gt;&gt;&gt;"))
                a = fn+sn
                print(a)
        if ac == 2:
                print("First number :")
                fn = float(input("&gt;&gt;&gt;"))
                print("Second number :")
                sn = float(input("&gt;&gt;&gt;"))
                a = fn-sn
                print(a)
        if ac == 3:
                print("First number :")
                fn = float(input("&gt;&gt;&gt;"))
                print("Second number :")
                sn = float(input("&gt;&gt;&gt;"))
                a = fn*sn
            print(a)
        if ac == 4:
                print("First number :")
                fn = float(input("&gt;&gt;&gt;"))
                print("Second number :")
                sn = float(input("&gt;&gt;&gt;"))
                a = fn/sn
                print(a)
        else:
                badnum()
print("\n"*100)
while True:
    try:
        main()
    except ValueError:
        badnum()
    except ZeroDivisionError:
        print("Infinity")
    print("\n"*100)
</code></pre>

<p>If I understand you correctly, you just need to replace second and further <code>if</code> with <code>elif</code>:</p>

<pre><code>if ac == 1:
...
elif ac == 2:
...   
if ac == 3:
...        
if ac == 4:
...        
else:
...
</code></pre>

<p>And "Invalid Number" will not be printed after each calculation.</p>

python python-3.x if-statement