I tried a make a calculator but it gives an error

Hi I’m new at the python and trying to make basic calculator, but when i try to start it gives a string is not int error, can u help me please?

def Add(number1, number2):
    return number1+number2
    
def Minus (number1, number2):
    return number1-number2
    
def Multiply (number1, number2):
    return number1*number2
    
def Divide (number1, number2):
    return number1/number2
    
print("Operation?")
print("1: Add")
print("2: Minus")
print("3: Multiply")
print("4: Divide")

operation= int(input("Please selecet an operation..."))
number1= int(input("Enter Number1"))
number2= int(input("Enter Number2"))

if operation==1:
    print("Answer= "+ int(number1+number2))
elif operation==2:
    print("Answer= "+ int(number1-number2))
elif operation==3:
    print("Answer= "+ int(number1*number2))
elif operatipn==4:
    print("Answer= "+ int(number1/number2))
else:
    print("You didn't choose anything in list")

>Solution :

The problem here is that you are trying to add an int object to a str object in the print statements:

print("Answer= "+ int(number1-number2))

you just need to convert it to str not an int because the result of the – or + operations on int objects will be int:

print("Answer= "+ str(number1-number2))

Leave a Reply