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

Julien Martin

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 +=: 'int' and 'list'

Here is the function called testIfCorrect:

def testIfCorrect(world, x, y):
    s=0
    for line in world:
        s+=line
        print("ligne",line)
        if(s > 2):
            return False
    for i in range(x):
        if(sum(returnColumn(world, i)) > 2):
            return False
    for j in range(x):
        for k in range(y):
            if(j == k):
                pass
            else:
                if(world[j] == world[k]):
                    return False
                if(returnColumn(world, j) == returnColumn(world ,k)):
                    return False

def returnColumn(array, column):
    return [col[column] for col in array]

Where is the error?

Sakib Ahammed

In

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

Here s is an int and wordis 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)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TypeError For Unsupported Operand type 'int' and 'list'

From Dev

typeError: unsupported operand type(s) for %: 'list' and 'int'

From Dev

unsupported operand types for //: 'str', 'int'

From Dev

Code throws TypeError: unsupported operand type(s) for -: 'int' and 'list'

From Dev

Cinema Booking Program: TypeError: unsupported operand type(s) for -: 'list' and 'int'

From Dev

builtins.TypeError: unsupported operand type(s) for +: 'int' and 'list'

From Dev

TypeError: unsupported operand type(s) for |: 'list' and 'list'

From Dev

TypeError: unsupported operand type(s) for -: 'list' and 'list'

From Dev

TypeError: unsupported operand type(s) for |: 'list' and 'list'

From Dev

TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand int and NoneType? Python

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

From Dev

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for |: 'int' and 'str'

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'Element'

From Dev

TypeError: unsupported operand type(s) for //: 'int' and 'graph'

From Dev

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for 'Instance' and 'Int'

From Dev

TypeError: unsupported operand type(s) for +=: 'int' and 'str'

From Dev

TypeError: unsupported operand type(s) for <<: 'int' and 'float'

From Dev

TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'instance'

From Dev

Python - Unsupported Operand type(s) for +: 'int' and 'list'

From Dev

unsupported operand type(s) for +=: 'int' and 'list'

From Dev

Unsupported operand type(s) for -=: 'list' and 'int'

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'list' when trying to split a text file

From Dev

Unsupported operand types 'NoneType'

From Dev

Django unsupported operand types

Related Related

  1. 1

    TypeError For Unsupported Operand type 'int' and 'list'

  2. 2

    typeError: unsupported operand type(s) for %: 'list' and 'int'

  3. 3

    unsupported operand types for //: 'str', 'int'

  4. 4

    Code throws TypeError: unsupported operand type(s) for -: 'int' and 'list'

  5. 5

    Cinema Booking Program: TypeError: unsupported operand type(s) for -: 'list' and 'int'

  6. 6

    builtins.TypeError: unsupported operand type(s) for +: 'int' and 'list'

  7. 7

    TypeError: unsupported operand type(s) for |: 'list' and 'list'

  8. 8

    TypeError: unsupported operand type(s) for -: 'list' and 'list'

  9. 9

    TypeError: unsupported operand type(s) for |: 'list' and 'list'

  10. 10

    TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

  11. 11

    TypeError: unsupported operand int and NoneType? Python

  12. 12

    TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

  13. 13

    TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

  14. 14

    TypeError: unsupported operand type(s) for |: 'int' and 'str'

  15. 15

    TypeError: unsupported operand type(s) for +: 'int' and 'Element'

  16. 16

    TypeError: unsupported operand type(s) for //: 'int' and 'graph'

  17. 17

    TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

  18. 18

    TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

  19. 19

    TypeError: unsupported operand type(s) for 'Instance' and 'Int'

  20. 20

    TypeError: unsupported operand type(s) for +=: 'int' and 'str'

  21. 21

    TypeError: unsupported operand type(s) for <<: 'int' and 'float'

  22. 22

    TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'

  23. 23

    TypeError: unsupported operand type(s) for +: 'int' and 'instance'

  24. 24

    Python - Unsupported Operand type(s) for +: 'int' and 'list'

  25. 25

    unsupported operand type(s) for +=: 'int' and 'list'

  26. 26

    Unsupported operand type(s) for -=: 'list' and 'int'

  27. 27

    TypeError: unsupported operand type(s) for +: 'int' and 'list' when trying to split a text file

  28. 28

    Unsupported operand types 'NoneType'

  29. 29

    Django unsupported operand types

HotTag

Archive