Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to divide array number
#1
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
Reply
#2
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.
Reply
#3
(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
Reply
#4
0 means pass and any other number means fail. (It is the remainder of the division.)
Reply
#5
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')
Reply
#6
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Divide a number by numbers in a list. Wallen 7 8,017 Feb-12-2022, 01:51 PM
Last Post: deanhystad
  How to add a number to each column separtely in numpy array? Oliver 0 1,483 Jul-02-2020, 02:55 PM
Last Post: Oliver
  how to divide one big equation entered as a string to small chunks gungurbuz 1 1,614 May-28-2020, 03:46 PM
Last Post: Larz60+
  Make an array of string number in a List polantas 5 3,089 May-27-2020, 07:18 AM
Last Post: buran
  Python calculator divide by zero help dock1926 4 5,827 Jan-20-2020, 05:15 PM
Last Post: michael1789
  Python don't divide SteLu 8 5,216 Dec-21-2017, 02:58 PM
Last Post: casevh

Forum Jump:

User Panel Messages

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