如果一个数字没有被 3 或 5 整除,我如何跳过加法

编程


令 N 位于 N 中。
编写一个函数,给出以下整数的总和 [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] 能被 3 整除 或者 5.

您可能需要仔细查看您的代码,看看您的代码是否符合该条件。

解决方案2

引用:

我不知道在其他部分该写什么

首先,你必须修复你的 if健康)状况。 按照建议,再次查看需求。 看看你的代码是否符合要求。
else 部分是可选的,如果不需要,则忽略它。

コメント

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