Comment puis-je ignorer l’ajout d’un nombre s’il n’est pas divisé par 3 ou 5

la programmation


Soit N dans N.
Écrire une fonction donnant la somme des entiers de [1,N[ divisibles par 3 ou 5.

Translation:
Let N be in N.
Write a function giving the sum of the integers of [1,N[ divisible by 3 or 5.

my answer was:

Python
N=eval(input("enter a number:"))
s=0
for i in range(1, N):
    if i%3==0 and i%5==0 :
        s=s+i
        print(s)
    else:

What I have tried:

i dont know what to write in the else part

Solution 1

First, you don’t have to specify an else if there’s nothing to do outside of the conditions you’ve been given.

Next, the program spec says

Quote:

Write a function giving the sum of the integers of [1,N] divisible par 3 ou 5.

Vous voudrez peut-être examiner votre code d’un peu plus près pour voir si votre code correspond à cette condition.

Solution 2

Citation:

je ne sais pas quoi écrire dans la partie else

Tout d’abord, vous devez réparer votre ifcondition. Comme suggéré, examinez à nouveau l’exigence. Vérifiez si votre code est conforme.
Le else une partie est facultative, si vous n’en avez pas besoin, omettez-la.

コメント

タイトルとURLをコピーしました