Search code examples
pythonpython-3.xmathsumreturn

Why is my function returning input1 and input2 as strings? I'm trying to create an addition function


    def addition():
            int(input1)
            int(input2)
            mysum = input1 + input2
            print(mysum)


    input1: str = input("Enter integer #1 \n ")
    input2: str = input("Enter integer #2 \n ")
    addition()


I tried to convert the inputs to ints so that I could add them together but it just treats them like regularly doing:

print(text1("1") + text2("1")

result: 11

I also tried to use sum() with a "for numbers in input1 and input2" statement but produced the same result.


Solution

  • Change your function to this

    def addition():
          mysum = int(input1) + int(input2)
          print(mysum)