Home > Article > Backend Development > 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)
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!