Python Forum

Full Version: TypeError: unsupported opperand type(s) for %: 'int' and 'list'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
nonprimenumbers=[]
primenumbers = []

for i in range (2,100000):
if (i%primenumbers==0):
nonprimenumbers.append
else:
primenumbers.append
print(primenumbers)
need answer ASAP
answer please
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.
(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
How do you normally do something with every item in a list?
recall them
What do you mean by "recall"? That's not a programming term.
(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.