![]() |
TypeError: unsupported opperand type(s) for %: 'int' and 'list' - 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: TypeError: unsupported opperand type(s) for %: 'int' and 'list' (/thread-37161.html) |
TypeError: unsupported opperand type(s) for %: 'int' and 'list' - cool_person - May-06-2022 nonprimenumbers=[] primenumbers = [] for i in range (2,100000): if (i%primenumbers==0): nonprimenumbers.append else: primenumbers.append print(primenumbers) need answer ASAP RE: TypeError: unsupported opperand type(s) for %: 'int' and 'list' - cool_person - May-07-2022 answer please RE: TypeError: unsupported opperand type(s) for %: 'int' and 'list' - ndc85430 - May-07-2022 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.
RE: TypeError: unsupported opperand type(s) for %: 'int' and 'list' - cool_person - May-07-2022 (May-07-2022, 06:17 AM)ndc85430 Wrote: Why do you think the expression then how do you divide by every number in a list RE: TypeError: unsupported opperand type(s) for %: 'int' and 'list' - ndc85430 - May-07-2022 How do you normally do something with every item in a list? RE: TypeError: unsupported opperand type(s) for %: 'int' and 'list' - cool_person - May-07-2022 recall them RE: TypeError: unsupported opperand type(s) for %: 'int' and 'list' - ndc85430 - May-07-2022 What do you mean by "recall"? That's not a programming term. RE: TypeError: unsupported opperand type(s) for %: 'int' and 'list' - ibreeden - May-07-2022 (May-07-2022, 06:21 AM)cool_person Wrote: recall themThere 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) In youre case you should do your computation instead of printing it.
|