def square_of_sum(L):
sum = 0
for x in L:
sum += x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for x in L:
sum += x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-04-24
def average(*args):
sum=0.0
for x in args:
sum=sum+x
t=len(args)
if t==0:
return 0.0
else:
return sum/t
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum=0.0
for x in args:
sum=sum+x
t=len(args)
if t==0:
return 0.0
else:
return sum/t
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-04-24
import math
def quadratic_equation(a, b, c):
if a==0:
return -c/b
elif b**2-4*a*c>=0:
return (-b+math.sqrt(b**2-4*a*c))/(2*a),(-b -math.sqrt(b**2-4*a*c))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
if a==0:
return -c/b
elif b**2-4*a*c>=0:
return (-b+math.sqrt(b**2-4*a*c))/(2*a),(-b -math.sqrt(b**2-4*a*c))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-04-24
def greet(x2 = 'world',x1 = 'hello,',x3 ='.'):
print x1,x2,x3
greet()
greet('Bart')
print x1,x2,x3
greet()
greet('Bart')
2015-04-24
各位不要纠结第四个了,这个就是让大家看看程序报错的效果IndexError: list index out of range
2015-04-23
sum = 0
x = 1
n = 1
while True:
sum = sum +x
x = 2 * x
n = n+1
if n> 20:
break
print sum
x = 1
n = 1
while True:
sum = sum +x
x = 2 * x
n = n+1
if n> 20:
break
print sum
2015-04-23
print [m+n+k for m in "123456789" for n in "0123456789" for k in "0123456789" if m==k] 貌似也可以吧??就是出现是字符不是数字
2015-04-23
已采纳回答 / Perona
这是HTML标签。由尖括号<>包围的关键词,比如 <html>。通常是成对出现的,比如 <div> 和 </div>。标签对中的第一个标签是开始标签,如<div>,第二个标签是结束标签,如</div>。<tr></tr>是表中的行,<td></td>是表中的单元格。
2015-04-23
谁能清楚的解释下这句代码意思? '<tr><td>%s</td><td>%s</td></tr>',另外其中的td、tr、和/td、/tr又有什么不同,为什么是采用<>括号?求扫盲。非常感谢
2015-04-23
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2015-04-23
print 'name:',k,'score:',d[k]
name: Lisa score: 85
name: Adam score: 95
name: Bart score: 59
输出这么美观都不让过,非要输出那么丑的形式。。。
name: Lisa score: 85
name: Adam score: 95
name: Bart score: 59
输出这么美观都不让过,非要输出那么丑的形式。。。
2015-04-23