python函数实现1到100的偶数和
时间: 2023-06-03 22:01:47 浏览: 1632
python-1到100偶数和.py
可以使用以下代码实现1到100的偶数和:
```python
def even_sum(start, end):
"""Calculate the sum of even numbers between start and end."""
total = 0
for i in range(start, end+1):
if i % 2 == 0:
total += i
return total
sum = even_sum(1, 100)
print("The sum of even numbers between 1 and 100 is", sum)
```
输出结果为:
```
The sum of even numbers between 1 and 100 is 2550
```
阅读全文