كيف يمكنني تخطي إضافة رقم إذا لم يكن مقسومًا على 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をコピーしました