First create variables i and sum respectively and define the initial values of the two variables as 0
The code is as follows:
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:
The result is as follows:
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!