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

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 :

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

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