Home >Backend Development >Python Tutorial >How to calculate the sum from 1 to 100 in python

How to calculate the sum from 1 to 100 in python

王林
王林Original
2020-05-08 11:47:1029912browse

How to calculate the sum from 1 to 100 in python

First create variables i and sum respectively and define the initial values ​​of the two variables as 0

The code is as follows:

How to calculate the sum from 1 to 100 in python

Then use the while loop statement to specify that when i is less than 100, enter the loop, and add 1 each time in the loop, sum adds the value of i each time through the loop, and finally use print to print out the value of sum.

The code is as follows:

How to calculate the sum from 1 to 100 in python

The result is as follows:

How to calculate the sum from 1 to 100 in python

Recommended tutorial: python tutorial

The above is the detailed content of How to calculate the sum from 1 to 100 in 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