0

just a quick question, how would i make it so that instead of just having 1 number (5 in this example) i could have multiple numbers (e.g. 5 or 6 or 7 etc.) or would i just have to do all of them seperately.

This is my example - if (i % 5 == 0):

i know it seems like a dumb question but i can't figure it out for some reason unless it's not possible. I've already tried if (i % 5 or 6 == 0): and if i % (5 or 6) == 0: but neither of them worked.

hope this makes sense thank you in advance

reddy
  • 23
  • 2

1 Answers1

1

You can use the 'mod' function from numpy, which will return the result as a list. And put the result in the any function, which will return True if at least one value has a remainder after division.

numpy.mod

import numpy as np

i = 10
aaa = np.any(np.mod(i, [1, 2, 3]))
print(aaa)

Output

True

Results the remainder is zero everywhere.

i = 10
aaa = np.any(np.mod(i, [1, 2, 5]))
print(aaa)

Output

False
inquirer
  • 4,286
  • 2
  • 9
  • 16