3. 使用Python编程,求1到100(包含100)间所有偶数的和。
#python 3.6输出结果如下:
#蔡军生
#http://blog.csdn.net/caimouse/article/details/51749579
#
Z = [x for x in range(1, 101) if x % 2 == 0]
print(Z)
x = sum(Z)
print('累加的和为:', x)
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]
累加的和为: 2550