0

I'm trying to make a simple calculator in Python. I'm asking for 2 numbers and then operating based on the operational character they choose. However, the variable is turned into a string type so I can't add, subtract, etc.

This is the code:

a = input("Enter first number")
print(a)
b = input("Enter second number")
print(b)
op = input("Choose operation by entering +, -, x, or /")

if(op == "+"):
    print(a+b)

elif(op == "-"):
    print(a-b)

elif(op == "x"):
    print(a*b)

elif(op == "/"):
    print(a/b)    
else:
    print("Sorry; input the correct operational character")
tripleee
  • 175,061
  • 34
  • 275
  • 318

1 Answers1

2

example:

a = input("Enter first number")
a = int(a)

Another way:

a = int(input("Enter first number"))
tripleee
  • 175,061
  • 34
  • 275
  • 318