标签:python 基础 line sts utf-8 ace odi python练习题 weight xrange
python 练习题:
#/usr/bin/python
#coding=utf-8
#@Time :2017/10/26 9:38
#@Auther :liuzhenchuan
#@File :练习题.py
#实现1--100所有数的和
sum = 0
for i in xrange(1,101):
sum += i
print sum
>>> 5050
#实现1--500 所有奇数的和
js = sum([i for i in xrange(1,501) if i %2 ==1])
print js
>>> 62500
#求 1+2!+3!+4!+....20!的和
a = xrange(1,21)
b=1
sum3=0
for i in a:
b *=i
sum3 +=b
print b
print sum3
>>> 2432902008176640000
2561327494111820313
#对指定一个list进行排序[2,32,43,453,54,6,576,5,7,6,8,78,7,89]
list1 = [2,32,43,453,54,6,576,5,7,6,8,78,7,89]
list1.sort()
print list1
>>> [2, 5, 6, 6, 7, 7, 8, 32, 43, 54, 78, 89, 453, 576]
python 基础 2.8 python练习题
标签:python 基础 line sts utf-8 ace odi python练习题 weight xrange
原文地址:http://www.cnblogs.com/lzcys8868/p/7735675.html