![]() |
Issue with affecting numbers to a variable - 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: Issue with affecting numbers to a variable (/thread-21303.html) |
Issue with affecting numbers to a variable - Adem - Sep-23-2019 hello , i'm trying to code with python, i get little bit of problems with affecting many numbers to a variable. Can someone tell me what is the issue in my code ? How can I solve it ? Thanks for helping a=[ 2, 4, 8, 17, 18021990] if a % 4==0: print ("I'm a multiple of 4") RE: Issue with affecting numbers to a variable - newbieAuggie2019 - Sep-23-2019 (Sep-23-2019, 08:34 PM)Adem Wrote: hello , i'm trying to code with python, i get little bit of problems with affecting many numbers to a variable. Can someone tell me what is the issue in my code ? How can I solve it ? Thanks for helping Hi! I'm also a newbie. You cannot operate (like with %) two different types of data, like 'lists' (a) and 'integers' (int), but you can twist it a little, taking one by one, all the elements from the list, like: a=[ 2, 4, 8, 17, 18021990] for x in a: if x % 4==0: print ("The number", x, "is a multiple of 4.")that produces the following output: All the best,
RE: Issue with affecting numbers to a variable - Gribouillis - Sep-23-2019 Adem Wrote:Can someone tell me what is the issue in my code ? How can I solve it ?The issue is that you define a as a list of numbers, which is perfect, but a list of numbers is not a multiple of 4 and the operation a % 4 is not defined for this type.You can solve it by defining more precisely what you are trying to achieve and the result you're expecting. RE: Issue with affecting numbers to a variable - Adem - Sep-24-2019 Thanks for helping , it s finally working! |