I made this simple python calculator, took me 30mins

from math import *

# Input Variables
num1 = float(input("Enter First Number: "))
op = str(input("Enter Operator: "))
num2 = float(input("Enter Second Number: "))
result = float(0)

# Calculator If Condition
if op == "+":
    result = num1 + num2
    print("The Result Is: " + str(result))

    # Calculator Stuff
    order = str(input("If You Need Any Of These Type It's Number \n"
                      "Absolute Value(1) | | Square Root(2) | Other(3) |No(4)"))
    if order == "1":
        result = float(abs(result))
        print("The Result Is: " + str(result))
    elif order == "2":
        result = float(sqrt(result))
        print("The Result Is: " + str(result))
    elif order == "3":
        order = str(input("Cubic Root(1) | Square(2) | Cube(3) | Power A Number(4) | No(5)"))
        if order == "1":
            result = float(cbrt(result))
            print("The Result Is: " + str(result))
        elif order == "2":
            result = float(pow(result, 2))
            print("The Result Is: " + str(result))
        elif order == "3":
            result = float(pow(result, 3))
            print("The Result Is: " + str(result))
        elif order == "4":
            result = pow(result, float(input("Enter Power: ")))
            print("The Result Is: " + str(result))
        elif order == "5":
            print("Thanks For Using Our Calculator")
        else:
            print("You Entered Invalid Number")
    elif order == "4":
        print("Thanks For Using Our Calculator")
    else:
        print("You Entered Invalid Number")

elif op == "-":
    result = num1 - num2
    print("The Result Is: " + str(result))

    # Calculator Stuff
    order = str(input("If You Need Any Of These Type It's Number \n"
                      "Absolute Value(1) | | Square Root(2) | Other(3) |No(4)"))
    if order == "1":
        result = float(abs(result))
        print("The Result Is: " + str(result))
    elif order == "2":
        result = float(sqrt(result))
        print("The Result Is: " + str(result))
    elif order == "3":
        order = str(input("Cubic Root(1) | Square(2) | Cube(3) | Power A Number(4) | No(5)"))
        if order == "1":
            result = float(cbrt(result))
            print("The Result Is: " + str(result))
        elif order == "2":
            result = float(pow(result, 2))
            print("The Result Is: " + str(result))
        elif order == "3":
            result = float(pow(result, 3))
            print("The Result Is: " + str(result))
        elif order == "4":
            result = pow(result, float(input("Enter Power: ")))
            print("The Result Is: " + str(result))
        elif order == "5":
            print("Thanks For Using Our Calculator")
        else:
            print("You Entered Invalid Number")
    elif order == "4":
        print("Thanks For Using Our Calculator")
    else:
        print("You Entered Invalid Number")

elif op == "*" or op == "X" or op == "x":
    result = num1 * num2
    print("The Result Is: " + str(result))

    # Calculator Stuff
    order = str(input("If You Need Any Of These Type It's Number \n"
                      "Absolute Value(1) | | Square Root(2) | Other(3) |No(4)"))
    if order == "1":
        result = float(abs(result))
        print("The Result Is: " + str(result))
    elif order == "2":
        result = float(sqrt(result))
        print("The Result Is: " + str(result))
    elif order == "3":
        order = str(input("Cubic Root(1) | Square(2) | Cube(3) | Power A Number(4) | No(5)"))
        if order == "1":
            result = float(cbrt(result))
            print("The Result Is: " + str(result))
        elif order == "2":
            result = float(pow(result, 2))
            print("The Result Is: " + str(result))
        elif order == "3":
            result = float(pow(result, 3))
            print("The Result Is: " + str(result))
        elif order == "4":
            result = pow(result, float(input("Enter Power: ")))
            print("The Result Is: " + str(result))
        elif order == "5":
            print("Thanks For Using Our Calculator")
        else:
            print("You Entered Invalid Number")
    elif order == "4":
        print("Thanks For Using Our Calculator")
    else:
        print("You Entered Invalid Number")


elif op == "/":
    result = num1 / num2
    print("The Result Is: " + str(result))

    # Calculator Stuff
    order = str(input("If You Need Any Of These Type It's Number \n"
                      "Absolute Value(1) | | Square Root(2) | Other(3) |No(4)"))
    if order == "1":
        result = float(abs(result))
        print("The Result Is: " + str(result))
    elif order == "2":
        result = float(sqrt(result))
        print("The Result Is: " + str(result))
    elif order == "3":
        order = str(input("Cubic Root(1) | Square(2) | Cube(3) | Power A Number(4) | No(5)"))
        if order == "1":
            result = float(cbrt(result))
            print("The Result Is: " + str(result))
        elif order == "2":
            result = float(pow(result, 2))
            print("The Result Is: " + str(result))
        elif order == "3":
            result = float(pow(result, 3))
            print("The Result Is: " + str(result))
        elif order == "4":
            result = pow(result, float(input("Enter Power: ")))
            print("The Result Is: " + str(result))
        elif order == "5":
            print("Thanks For Using Our Calculator")
        else:
            print("You Entered Invalid Number")
    elif order == "4":
        print("Thanks For Using Our Calculator")
    else:
        print("You Entered Invalid Number")


elif op == "%":
    result = num1 % num2
    print("The Result Is: " + str(result))

    # Calculator Stuff
    order = str(input("If You Need Any Of These Type It's Number \n"
                      "Absolute Value(1) | | Square Root(2) | Other(3) |No(4)"))
    if order == "1":
        result = float(abs(result))
        print("The Result Is: " + str(result))
    elif order == "2":
        result = float(sqrt(result))
        print("The Result Is: " + str(result))
    elif order == "3":
        order = str(input("Cubic Root(1) | Square(2) | Cube(3) | Power A Number(4) | No(5)"))
        if order == "1":
            result = float(cbrt(result))
            print("The Result Is: " + str(result))
        elif order == "2":
            result = float(pow(result, 2))
            print("The Result Is: " + str(result))
        elif order == "3":
            result = float(pow(result, 3))
            print("The Result Is: " + str(result))
        elif order == "4":
            result = pow(result, float(input("Enter Power: ")))
            print("The Result Is: " + str(result))
        elif order == "5":
            print("Thanks For Using Our Calculator")
        else:
            print("You Entered Invalid Number")
    elif order == "4":
        print("Thanks For Using Our Calculator")
    else:
        print("You Entered Invalid Number")


else:
    print("You Entered Invalid Operator")

Do you have a question about your code?

1 Like

Yes, whenever I enter a letter in num1 or num2 while using the calculator, it gives an error I want to prevent this error from happening

What’s the error? What have you tried for debugging?

Enter First Number: t
Traceback (most recent call last):
File “c:\Users\Abdallah\OneDrive\Desktop\Python\Advanced Calculator.py”, line 15, in
if op == “+”:
^^
NameError: name ‘op’ is not defined

Ok. And what have you tried so far with debugging?

That variable certainly seems defined in the code you posted

You know what it would had been encouraging? If you would had answer @JeremyLT second question. Let me help you, if I may, to show you how debugging can be accomplished.
In your terminal enter python.
Then enter op at the prompt and take a look at the message. After that, if still you do not have a clue, try to search for python and the error message and see what you can find.