vendredi 27 novembre 2020

Loop computation - Sum of integers that are devidable

I am looking for a way to compute the sum of integers between 1 and 20 that can be divided by 2, 3 or 5.

I created an array with the integers from 1 to 20. Y= np.arange(1, 21, 1)

However I am not sure how to check if the integers can be divided by 2, 3 or 5. If I try the following I get a float and cannot convert it to an integer: X = Y/2

I know the computation and checking should be done in loop, potentially if loop that checks if Y can be divided by 2, 3 or 5 and then if the statement is true make the true statements add up. How can I do that?

Much thanks in advance!

Aucun commentaire:

Enregistrer un commentaire