Python Forum

Full Version: unsupported operand type(s) for %: 'list' and 'int'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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)
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']
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
Look at your append. You need ()