Create a python code to sum the number from 1 to 10.

We can do this using a for loop to iterate through the digits from 1 to 10 and add their values to a variable holding the values of the sum. We do this with the code below:summation = 0 #this will hold the current value of the sum for i in range(10): #i will start with the value 0 and increase until it is 9 so we use value i+1 for the items in our sum   summation += i+1 #we add the value of the current item to the sum print(summation) #we print the final value of the sum

ML

Related Python Mentoring answers

All answers ▸

What is the outcome of the following code? print(2*[3,4,5])


Why are negative indexes used?


Create a program that generates prime numbers between two integer boundareis


Give a segment of python code that will print the numbers 1 to 7, each one on a new line