-3

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)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

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)
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218