It seems that my code isn't converting integers in a list to strings. Here is the are of my code with the problem:
def aidrawboard(aiboard):
for i in aiboard:
inttostr = aiboard[i]
str(inttostr)
aiboard[i] = inttostr
for i in aiboard:
if aiboard[i] == '3':
aiboard[i] = '0'
break
print(aiboard)
print("THIS IS THE AI BOARD")
print(' | |')
print(' ' + aiboard[7] + ' | ' + aiboard[8] + ' | ' + aiboard[9])
print(' | |')
print('-----------')
print(' | |')
print(' ' + aiboard[4] + ' | ' + aiboard[5] + ' | ' + aiboard[6])
print(' | |')
print('-----------')
print(' | |')
print(' ' + aiboard[1] + ' | ' + aiboard[2] + ' | ' + aiboard[3])
print(' | |')
The code is for a battleship game. an example of list aiboard is [0, 0, 2, 0, 0, 0, 0, 0, 0, 0]
I get the error "TypeError: Can't convert 'int' object to str implicitly", with the error pointing to
print(' ' + aiboard[7] + ' | ' + aiboard[8] + ' | ' + aiboard[9])
Sorry if the error is very newbish. This is my first year coding.
str()returns a string, it doesn't convert an into to a string inplace.