python 1到n偶数求和

2025-02-11 23:03:33
推荐回答(1个)
回答1:

n=int(input("请输入整数:"))
print("1到n的偶数和为%s"%sum([i for i in range(n+1) if i%2==0]))