I have this python program that adds strings to integers:
a = raw_input("Enter a: ")
b = raw_input("Enter b: ")
print "a + b as strings: " + a + b
a = int(a)
b = int(b)
c = a + b
str(c)
print "a + b as integers: " + c
I get this error:
TypeError: cannot concatenate 'str' and 'int' objects
How can I add strings to integers?
There are two ways to fix the problem which is caused by the last
printstatement.You can assign the result of the
str(c)call tocas correctly shown by @jamylak and then concatenate all of the strings, or you can replace the lastprintsimply with this:in which case
isn’t necessary and can be deleted.
Output of sample run:
with: