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

Use while to find the sum from 1 to 100

silencement
Release: 2019-06-25 10:51:24
Original
55445 people have browsed it

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)
Copy after login

The output result is

5050
Copy after login

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!

Related labels:
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
Latest Issues
while loop
From 1970-01-01 08:00:00
0
0
0
An error occurred while accessing the login page
From 1970-01-01 08:00:00
0
0
0
java - Questions about While,break
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template