Python Forum
how to divide array number - 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: how to divide array number (/thread-23334.html)



how to divide array number - chinting - Dec-23-2019

Array = [1,33,99,199,25]

I would like to ask how can write a code to arrange my array number can be divided by 3 and 5
can anyone help me thanks.

for example

33,99 can divide by 3
25 can divide by 5


RE: how to divide array number - ibreeden - Dec-23-2019

Use the modulo operator %. This gives the remainder of a division. If the result is 0 then the number can be devided.
>>> 1 % 3
1
>>> 33 % 3
0
>>> 99 % 3
0
>>> 199 % 3
1
>>> 25 % 3
1
And after that you can do the same with 5.


RE: how to divide array number - chinting - Dec-23-2019

(Dec-23-2019, 10:20 AM)ibreeden Wrote: Use the modulo operator %. This gives the remainder of a division. If the result is 0 then the number can be devided.
 >>> 1 % 3 1 >>> 33 % 3 0 >>> 99 % 3 0 >>> 199 % 3 1 >>> 25 % 3 1 
And after that you can do the same with 5.
0 mean is pass meaning and 1 fails meaning right


RE: how to divide array number - ibreeden - Dec-24-2019

0 means pass and any other number means fail. (It is the remainder of the division.)


RE: how to divide array number - chinting - Dec-30-2019

May I ask if I used for loop to single checking the number, the code can how to write.
foo = [1,33,99,199,25]
for char in foo:
if char % 3:
print('ok')
else:
print('ng')


RE: how to divide array number - ibreeden - Dec-30-2019

Please format your code according to the rules. Use [python] at the start of the code block and [/python] at the end. Read BBCode how to do this.