Home  >  Article  >  Backend Development  >  How to calculate the sum from 1 to 100 using python?

How to calculate the sum from 1 to 100 using python?

coldplay.xixi
coldplay.xixiOriginal
2020-06-09 15:41:1730218browse

How to calculate the sum from 1 to 100 using python?

How to calculate the sum from 1 to 100 using python?

The code for python to calculate the sum of 1 to 100 is as follows:

sum = 0
for i in range(1,101):
    sum = sum + i
print(sum)

Output result: 5050

Recommended tutorial: " Pyrhon video tutorial

The above is the detailed content of How to calculate the sum from 1 to 100 using python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn