Python Forum
unsupported operand type(s) for %: 'list' and 'int'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unsupported operand type(s) for %: 'list' and 'int'
#1
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
Reply
#2
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)
BashBedlam likes this post
Reply
#3
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']
Reply
#4
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
Reply
#5
Look at your append. You need ()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Type Error: Unsupported Operand jhancock 2 1,067 Jul-22-2023, 11:33 PM
Last Post: jhancock
  search a list or tuple for a specific type ot class Skaperen 8 1,853 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 9,207 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,096 May-07-2022, 08:40 AM
Last Post: ibreeden
  You have any idea, how fix TypeError: unhashable type: 'list' lsepolis123 2 2,965 Jun-02-2021, 07:55 AM
Last Post: supuflounder
  unsupported operand type(s) for /: 'str' and 'int' Error for boxplot soft 1 3,022 Feb-09-2021, 05:40 PM
Last Post: soft
  What type of *data* is the name of a list/tuple/dict, etc? alloydog 9 4,253 Jan-30-2021, 07:11 AM
Last Post: alloydog
Question dict value, how to change type from int to list? swissjoker 3 2,691 Dec-09-2020, 09:50 AM
Last Post: perfringo
  unsupported operandtype(s) for -: 'list' and 'int' Lakkad 2 3,552 Apr-27-2020, 10:16 AM
Last Post: pyzyx3qwerty
  calculate_bai -- TypeError: unsupported operand type(s) for *: 'float' and 'NoneType' pantherd 1 3,195 Apr-21-2020, 12:31 PM
Last Post: anbu23

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020