हिंदी

The code given below accepts N as an integer argument and returns the sum of all integers from 1 to N. Observe the following code carefully and rewrite it after removing all syntax and logical - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

The code given below accepts N as an integer argument and returns the sum of all integers from 1 to N. Observe the following code carefully and rewrite it after removing all syntax and logical errors. Underline all the corrections made.

def Sum(N)
    for I in range(N):
        S=S+I
    return S
print(Sum(10)
कोड लेखन
Advertisements

उत्तर

def Sum(N): Missing Colon
         for I in range(1,(N+1)): Incorrect loop – Should be from1 to N+1
              S=S+I
          return S
print(Sum(10)) Braces missing

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2024-2025 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×