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
Hindi,
2 months ago
Political Science,
2 months ago
Biology,
2 months ago
Math,
4 months ago
India Languages,
4 months ago
Hindi,
1 year ago
Physics,
1 year ago