Home > Backend Development > Python Tutorial > How to sum even numbers in python1-100?

How to sum even numbers in python1-100?

coldplay.xixi
Release: 2020-06-30 09:57:20
Original
56679 people have browsed it

How to sum even numbers in python1-100?

Recommended tutorial: "Python Video Tutorial"

How to sum even numbers in python1-100?

Python method of summing even numbers:

#求100内偶数while\for..in循环
sum = 0
i = 0
while i <=100:
    sum += i
    i += 2
print(sum)
 
 
sum = 0
#range函数end时不包括当前数值,所有注意101.
for i in range(0,101,2):
    sum += i
print(sum)
Copy after login

Result:

The sum of even numbers between 1-100 is: 2550

Recommended related articles: "python tutorial"

The above is the detailed content of How to sum even numbers in python1-100?. 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