1
votes

I have been having some issues with a line of code in a program I'm making. when ever I run the file it displays this message:

Traceback (most recent call last):
  File "C:\Users\Main\Google Drive\computerprograming\mathoperationscalc.py", line 9, in <module>
    print('the sum of ' + x + ' and ' + y + ' is ')
TypeError: Can't convert 'int' object to str implicitly

Here is the code:

print('please input 1st integer')
x = input()
x = int(x)
print('please input 2nd integer')
y = input()
y = int(y)

Sum = x + y
print('the sum of ' + x + ' and ' + y + ' is ')
print(Sum)
1
(Or any of the 650 other SO questions you'd get if you'd bothered to Google the error message.) - jonrsharpe

1 Answers

0
votes

You need to convert the int to str you so you can concatenate.

x = int(input('please input 1st integer'))
y = int(input('please input 2nd integer'))

total = x + y
print('the sum of ' + str(x) + ' and ' + str(y) + ' is ')
print(Sum)

Or use format

'the sum of {} and {} is {}'.format(x,y,total)