I am trying to do a project in python. I\'m getting an error in the line
s+=line
TypeError: unsupported operand type(s) for +=:
In
s=0
for line in world:
s+=line
Here s
is an int and word
is 2D List. So, In for line in world
, line
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)