0
a = input('1st number: ')
b = input('2nd number: ')
c = a + b
print(a + ' + ' + b + ' = ' + c)

If I enter 1 for a then 2 for b it returns 12 instead of 3 and I don't understand why it wont find the sum of the two variables. Could anyone help I started with Java and I'm new to Python.

Max Holm
  • 15
  • 4
  • inputs are strings by default, you need to convert them to integer with int(), see tons of other questions with that – B. Go Oct 19 '19 at 21:06

1 Answers1

1

input() returns a string. So basically you have a = '1', b = '2' and c = a + b = '12'.

You need to cast a and b to int like a = int(a), b = int(b) then you'd get c = 3

Xnkr
  • 564
  • 5
  • 16