TypeError: unsupported operand type(s) for +=: ‘int’ and ‘list’

In

s=0
for line in world:
    s+=line

Here s is an int and wordis 2D List. So, In for line in worldline is a 1D List. It is impossible to add a List into a int type. Here, s+=line in incorrect

So, In s+=line, you can replace s+=sum(line). I think you have found your answer.

Try this:

s=0
for line in world:
    s+=sum(line)

Leave a Comment