[issue7393] Executing Python program of sum of 2 nos.

Raymond Hettinger report at bugs.python.org
Wed Nov 25 08:19:23 CET 2009

Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

In Python 3.1, the input() function always returns a string.  In your
case, the string is "21".  Adding two strings together gives you a
longer string:  "12" + "34" --> "1234".

To get your program to do what you want, convert the string to a number
using int():

a = int(input('give a number: '))
b = int(input('and another: '))
print('the sum is', a + b)

nosy: +rhettinger
resolution:  -> invalid
status: open -> closed

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list