def generate_tr(name, score):
if(score>=60):
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
其余不变
if(score>=60):
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
其余不变
2017-01-16
def square_of_sum(L):
N=0
i=0
for t in L:
if i<5 :
t=L[i]
i=i+1
N=N+t*t
return N
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
N=0
i=0
for t in L:
if i<5 :
t=L[i]
i=i+1
N=N+t*t
return N
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2017-01-16
def move(n, a, b, c):
if n == 1:
print(a+'-->'+c)
return
else:
move(n-1, a, c, b)
print(a+'-->'+c)
move(n-1,b,a,c)
move(3,'A','B','C')
if n == 1:
print(a+'-->'+c)
return
else:
move(n-1, a, c, b)
print(a+'-->'+c)
move(n-1,b,a,c)
move(3,'A','B','C')
2017-01-15
sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=x*2
n=n+1
if n=20:
break
print sum
x = 1
n = 1
while True:
sum=sum+x
x=x*2
n=n+1
if n=20:
break
print sum
2017-01-15
已采纳回答 / 钺箜
同楼上IDLE提示list对象不可调用把L(i)改成L[i]就对了用小括号的时候,L被当作一个函数了,而L在这是个list,所以不可调用用中括号可以获取list的元素参考回答见http://stackoverflow.com/questions/18758186/typeerror-list-object-is-not-callable<...图片...>
2017-01-15
为什么要区分整数运算和浮点数运算呢?这是因为整数运算的结果永远是精确的,而浮点数运算的结果不一定精确,因为计算机内存再大,也无法精确表示出无限循环小数,比如 0.1 换成二进制表示就是无限循环小数。
2017-01-15
def square_of_sum(L):
List = []
for n in L:
List.append(n**2)
return sum(List)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
List = []
for n in L:
List.append(n**2)
return sum(List)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2017-01-15