Python Forum
unsupported operand type(s) for %: 'list' and 'int' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: unsupported operand type(s) for %: 'list' and 'int' (/thread-14210.html)



unsupported operand type(s) for %: 'list' and 'int' - RandomCoder - Nov-20-2018

a = []
k=1
for x in range(0,10):
    a.append(int(input()))
for x in range(0,30):
    if (a%2==0):
        k=k*a
print(k)
need answer ASAP


RE: unsupported operand type(s) for %: 'list' and 'int' - stullis - Nov-20-2018

Because "a" is a list, you cannot simply perform mathematics with it. You can iterate over "a" and take the modulus of each number in it:

a = []
k=1

for x in range(0,10):
    a.append(int(input()))
    
for x in a:
    if (x % 2 == 0):
        k *= x

print(k)



RE: unsupported operand type(s) for %: 'list' and 'int' - Larz60+ - Feb-22-2022

to get your list:
for numeric:
a = list(num for num in range (0, 11))
print(a)
Output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
a = list(str(num) for num in range (0, 11))
print(a)
Output:
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']



RE: unsupported operand type(s) for %: 'list' and 'int' - cool_person - May-07-2022

nonprimenumbers=[]
primenumbers = []
for i in range (2,100000):
  if (i%primenumbers==0):
    nonprimenumbers.append 
else: 
  primenumbers.append 
  print(primenumbers)
Output:
Traceback (most recent call last): File "main.py", line 8, in <module> if (i % primenumbers == 0): TypeError: unsupported operand type(s) for %: 'int' and 'list'
answer ASAP


RE: unsupported operand type(s) for %: 'list' and 'int' - menator01 - May-07-2022

Look at your append. You need ()