1 + 1 = 11 not 2


#1

So i have my code and it doesnt add up numbers it just 1 + 1 = 11 not 2 or “3 +3 = 33” “5 + 1 = 51” and so on. How do i fix this

if input2 == "calculator":
    print("1 = + , 2 = - , 3 = *, 4 = / ")
    a = input("Type number  ")
    b = input("Type another number  ")
    x = input("Multiply,add....?  ")
    if x == "1":
        print(a + b)
    elif x == "2":
        print(a - b)
    elif x == "3":
        print(a * b)
    elif x == "4":
        print(a / b)

other operations dont even work

Traceback (most recent call last):
  File "C:\Users\USER\AppData\Local\atom\Computer.py", line 48, in <module>
    print(a * b)
TypeError: can't multiply sequence by non-int of type 'str'

Process returned 1 (0x1)        execution time : 8.750 s
Press any key to continue . . .

#2

what you do there is string concatenation, example:

print("a" + "b")

you do the same with "1" and "2", to the proper maths, you need integers, not strings


#3

Hmm i still dont quite understand…
i tried this but now it doesnt even print

a = int(input("Type number  "))
    b = int(input("Type another number  "))
    x = int(input("Multiply,add....?  "))

im kinda confused here…


#4

did you make changes at comparison operators as well? 1 == "1" is false, given they are different data types


#5

Thanks alot i fixed it now!!


#6

understanding the data structure and data types you want to use in a program is fundamental.