यदि कोई संख्या 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をコピーしました