Advertisements
Advertisements
Question
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)Code Writing
Advertisements
Solution
def Sum(N): Missing Colon
for I in range(1,(N+1)): Incorrect loop – Should be from1 to N+1
S=S+I return Sprint(Sum(10)) Braces missing
shaalaa.com
Is there an error in this question or solution?
2024-2025 (March) Set 4
