¿Cómo evito sumar un número si no está dividido entre 3 o 5?

programación


Sea N en N.
Escribe una función que dé la suma de los números enteros 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 por 3 o 5.

Es posible que desee mirar un poco más de cerca su código para ver si coincide con esa condición.

Solución 2

Cita:

No sé qué escribir en la parte más.

Primero, tienes que arreglar tu ifcondición. Como se sugirió, mire nuevamente el requisito. Vea si su código cumple.
El else La parte es opcional, si no la necesita, omítala.

コメント

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