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
Answered by Matthew L. Python tutor

2001 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Write a short program to print all the even numbers 1 to 100


[Student query] Why do we import libraries/modules such as Numpy and Matplotlib into Python?


How do I define a function in Python?


Create a program that takes in two numbers and returns the highest of the two


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences