How to calculate the sum from 1 to 100 in python

王林
Release: 2020-05-08 11:47:10
Original
29845 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template