27.7k views
2 votes
Write a python program called loop that computes and prints the sum of numbers from 1 to 10

User Benedikt B
by
4.8k points

1 Answer

5 votes

Here is code in Python.

# variable to store sum of numbers from 1 to 10

sum=0

for i in range(1,11):

#calculating the sum

sum+=i

#printing the sum

print("sum of numbers from 1 to 10 is:")

print(sum)

Step-by-step explanation:

Declare a variable "sum" to store the sum of all the numbers from 1 to 10.

In the for loop i will iterate from 1 to 10 only and each value of i is added to

"sum". then it will print the sum of all the number.

Output:

sum of numbers from 1 to 10 is:

55

User Alex Sexton
by
5.4k points