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.
print("Select an action ")
print("1.) Add")
print("2.) Subtract")
print("3.) Multiply")
print("4.) Divide")
ac = int(input(">>>"))
print("First number :")
fn = float(input(">>>"))
print("Second number :")
sn = float(input(">>>"))
if ac == 1:
print(fn + sn)
if ac == 2:
print(fn - sn)
if ac == 3:
print(fn * sn)
if ac == 4:
print(fn / sn)
else:
print("Invalid Number")
print("Press enter to continue")
input()
An example (wrong) output is:
Select an action
1.) Add
2.) Subtract
3.) Multiply
4.) Divide
>>>1
First number :
>>>2
Second number :
>>>3
5.0
Invalid Number
Press enter to continue
How can I fix that so "Invalid Number" only prints when it should?
if...elif, not those separateifblocks. And I wonder what that singleinput("")is supposed to do