Python Forum
TypeError: unsupported opperand type(s) for %: 'int' and 'list'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: unsupported opperand type(s) for %: 'int' and 'list'
#1
nonprimenumbers=[]
primenumbers = []

for i in range (2,100000):
if (i%primenumbers==0):
nonprimenumbers.append
else:
primenumbers.append
print(primenumbers)
need answer ASAP
Reply
#2
answer please
Reply
#3
Why do you think the expression i % primenumbers makes sense when primenumbers is a list? a % b means "give me the remainder when dividing a by b" and division is done with single numbers, not lists of numbers.
Reply
#4
(May-07-2022, 06:17 AM)ndc85430 Wrote: Why do you think the expression i % primenumbers makes sense when primenumbers is a list? a % b means "give me the remainder when dividing a by b" and division is done with single numbers, not lists of numbers.

then how do you divide by every number in a list
Reply
#5
How do you normally do something with every item in a list?
Reply
#6
recall them
Reply
#7
What do you mean by "recall"? That's not a programming term.
Reply
#8
(May-07-2022, 06:21 AM)cool_person Wrote: recall them
There are several ways to "recall" the items in a list, but in your case the easyest way is to iterate over them.
primenumbers = [2,3,5,7,11]
for i in primenumbers:
    print(i)
Output:
2 3 5 7 11
In youre case you should do your computation instead of printing it.
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,852 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 9,206 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,755 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  unsupported operand type(s) for %: 'list' and 'int' RandomCoder 4 32,700 May-07-2022, 08:07 AM
Last Post: menator01
  TypeError: list indices must be integers or slices, not range Anldra12 2 2,499 Apr-22-2022, 10:56 AM
Last Post: Anldra12
  You have any idea, how fix TypeError: unhashable type: 'list' lsepolis123 2 2,965 Jun-02-2021, 07:55 AM
Last Post: supuflounder
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 7,323 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  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,252 Jan-30-2021, 07:11 AM
Last Post: alloydog

Forum Jump:

User Panel Messages

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