Write a programme to display the sum of numbers from 50 to 1
Answers
Answered by
4
Solution:
The given code is written in Python 3.
s=0
for i in range(1,51):
s+=i
print("Sum of numbers from 1 to 50 is:",s)
OR,
s=sum([i for i in range(1,51)])
print("Sum of numbers from 1 to 50 is:",s)
Logic:
- Initialise s = 0
- Loop through numbers in the range 1 to 50.
- Add up the numbers and store in s.
- Display the value of s at last.
See the attachment for output.
Attachments:
Similar questions