total = 0
for i in range(0, some upper bound):
total += i
Sorry if this is basic but I have a lot of these and they’re taking up more room than is comfortable.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
or
The first one is Python, the second one Gauss.
EDIT: When not starting at zero:
or, again according to Gauss, do the same with
upperand substract the same forlower:If you are on Python 2.x, replace all
rangewithxrange.