python programming to find the sum of natural number
Answers
Answered by
2
Answer:
This is the Python program to find the sum of natural numbers upto n terms.
1. Using loop.
n=int(input("Enter limit - "))
s=0
for i in range(1,n+1):
s+=i
print("Sum: ",s)
2. Using sum function.
n=int(input("Enter limit - "))
s=sum([i for i in range(1,n+1)])
print("Sum: ",s)
Algorithm:
- START.
- Accept the limit (n).
- Initialise s = 0
- Iterate a loop in the range i = 1 to n.
- Add the value of 'i' in s.
- Display the value of s.
- STOP.
See the attachment for output ☑.
Attachments:
Similar questions