Can someone help me with this simple calculator program in python? I am having problem in finding error

Program got a Syntax error as follow:

elif choice == "3":
^^^^
SyntaxError: invalid syntax

print("1 Addition\n2 Subtraction\n3 Multiplication\n4 Division ")
choice= input ("WHat is you choice? : ")
num1 = float (input("Please enter a number: "))
num2 = float( input("please enter another number: "))

if choice == "1":
    print(Num1,"+", Num2, "=", (Num1 + Num2))
    elif choice == "2":
    print(Num1,"-", Num2, "=", (Num1 - Num2))
    elif choice == "3":
    print(Num1,"x", Num2, "=", (Num1 * Num2))
    elif choice == "4":
        if Num2 == 0.0
            print("0 error LOL")
        else:
            print(Num1, "/", Num2, "=", (Num1 / Num2) )
else:
    print("your choice is bad...")
    

>Solution :

Variable names are case sensitive ("num1" cannot be referenced as "Num1")

Indentation on elif should be inline with the original "if"

Missing colon on if statement on line 13.

Here is an altered version that worked for me:

print("1 Addition\n2 Subtraction\n3 Multiplication\n4 Division ")
choice= input ("WHat is you choice? : ")
num1 = float (input("Please enter a number: "))
num2 = float( input("please enter another number: "))

if choice == "1":
    print(num1,"+", num2, "=", (num1 + num2))
elif choice == "2":
    print(num1,"-", num2, "=", (num1 - num2))
elif choice == "3":
    print(num1,"x", num2, "=", (num1 * num2))
elif choice == "4":
        if num2 == 0.0:
            print("0 error LOL")
        else:
            print(num1, "/", num2, "=", (num1 / num2) )
else:
    print("your choice is bad...")

Leave a Reply