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

Answered by Matthew L. Python tutor

1882 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Whats the output of "for i in "hello world": print(i)" and why/how is this achieved


Sales is real Customers is integer startmainprog input Sales input Customers if ((Sales > 500) OR ((Sales > 300) AND (Customers>9))) then output “Bonus Awarded” else output “No Bonus” end if end subroutine. Sales = 600 Customers = 9, answer:


Using the shared code editor, write a recursive function for calculating a factorial of an input parameter.


Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences