Here a short answer :
the value that you want is ‘w’ which is a string
but in line 3-5 you are executing code for integer
using the list,length and index of list
Rather than this try to code:
write() with an string
Then It will work
1
solved Error when writing file