Home  >  Article  >  Backend Development  >  Use while to find the sum from 1 to 100

Use while to find the sum from 1 to 100

silencement
silencementOriginal
2019-06-25 10:51:2455367browse

Use while to find the sum from 1 to 100

sum = 0
i = 1
while i<=100:
    sum = sum + i
    i += 1
print(&#39;1到100累积和:%d&#39;% sum)

The output result is

5050

The above is the detailed content of Use while to find the sum from 1 to 100. 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