python二级练习(3)

时间:2023-02-13 12:02:55

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

深入浅出Matplotlib
https://edu.csdn.net/course/detail/6859

深入浅出Numpy
http://edu.csdn.net/course/detail/6149 

Python游戏开发入门