Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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...")
    

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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...")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading