L = [75, 92, 59, 68]
sum = 0.0
for score in L:
sum = sum + score
print sum / 4
sum = 0.0
for score in L:
sum = sum + score
print sum / 4
2017-02-04
天哪,这段代码好长啊
# -*- coding: utf-8 -*-
#
# File Desc : conditional filter
# Author : wallace_lai
# At : 2017-02-04 00:33
print [100 * i + 10 * j + k for i in range(1, 10) for j in range(0, 10) for k in range(1, 10) if i == k]
# -*- coding: utf-8 -*-
#
# File Desc : conditional filter
# Author : wallace_lai
# At : 2017-02-04 00:33
print [100 * i + 10 * j + k for i in range(1, 10) for j in range(0, 10) for k in range(1, 10) if i == k]
2017-02-04
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }
def generate_tr(name, score):
if score < 60:
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name, score) for name, score in d.iteritems()]
def generate_tr(name, score):
if score < 60:
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name, score) for name, score in d.iteritems()]
2017-02-04
sum = 0
x = 1
n = 1
while True:
if n>20
break
sum+=x
x=x*2
n+=1
print sum
x = 1
n = 1
while True:
if n>20
break
sum+=x
x=x*2
n+=1
print sum
2017-02-03
最新回答 / wallace_lai
同学,你好。python的list集合支持sort()方法,你可以将数据放入list中,然后调用sort()方法进行排序。比如下面的例子:l = [45, 31, 29, 79, 84, 73, 61, 22, 13, 60]print ll.sort()print l运行结果为:[45, 31, 29, 79, 84, 73, 61, 22, 13, 60][13, 22, 29, 31, 45, 60, 61, 73, 79, 84]
2017-02-03
print 45678+0x12fd2
print 'Learn Python in imooc'
print 100<99
print 0xff==255
print 'Learn Python in imooc'
print 100<99
print 0xff==255
2017-02-03
已采纳回答 / wallace_lai
同学你好。cd是change directory(更改目录)的英文缩写。它的功能是更改当前的工作目录。1:举个例子,当我们打开windows下的cmd命令行的时候,默认的工作目录是:C:\Users\kkjl(kkjl是用户名)i...
2017-02-03
已采纳回答 / 慕粉1410442344
几乎所有编程语言都有list--数组 这一概念, 就不阐述了tuple是特殊的数组,当你创立一个数组只对其遍历时,由于tuple无需被更改,所以tuple相比一般list速度更快其次是保证数组的安全性,使其不便于不相关的更改
2017-02-03
公式记不住不要紧嘛,只要想一想便能推导出来。
因为是等差数列,所以第二个数与第一个数相差了1个公差d,由此可知第100个数和第一个数相差了99个公差,因此x100 = x1 + 99*d
求和的话,由于「第一项和最后一项之和」等于「第二项和倒数第二项之和」,由此类推发现100个数之和其实就等于50个「第一项和最后一项之和」相加,因此s = (x1 + x100) * 50
因为是等差数列,所以第二个数与第一个数相差了1个公差d,由此可知第100个数和第一个数相差了99个公差,因此x100 = x1 + 99*d
求和的话,由于「第一项和最后一项之和」等于「第二项和倒数第二项之和」,由此类推发现100个数之和其实就等于50个「第一项和最后一项之和」相加,因此s = (x1 + x100) * 50
2017-02-03
感觉答案太粗暴了,所以我‘化简为繁’写了下
t = ('a', 'b', ['A', 'B'])
t = list(t) #t = ['a', 'b', ['A', 'B']]
l = t[2] #l = ['A', 'B']
t.pop(2) #t = ['a', 'b']
l = tuple(l) #l = ('A', 'B')
t.append(l) #t = ['a', 'b',('A', 'B')]
t = tuple(t) #t = ('a', 'b',('A', 'B'))
print t
t = ('a', 'b', ['A', 'B'])
t = list(t) #t = ['a', 'b', ['A', 'B']]
l = t[2] #l = ['A', 'B']
t.pop(2) #t = ['a', 'b']
l = tuple(l) #l = ('A', 'B')
t.append(l) #t = ['a', 'b',('A', 'B')]
t = tuple(t) #t = ('a', 'b',('A', 'B'))
print t
2017-02-03