def average(*args):
L=args
if len(L) ==0:
return
i=0
s=0.0
for l in L:
i=i+1
s=l+s
return s/i
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
L=args
if len(L) ==0:
return
i=0
s=0.0
for l in L:
i=i+1
s=l+s
return s/i
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-11-28
def greet(ss='world'):
print 'hello,',ss
greet()
greet('Bart')
print 'hello,',ss
greet()
greet('Bart')
2015-11-28
不错,兄台我看好你!下一节吧。
def move(n, a, b, c):
if n ==1:
print a,"->>",c
else:
move(n-1,a,c,b)
print a,"->>",c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
def move(n, a, b, c):
if n ==1:
print a,"->>",c
else:
move(n-1,a,c,b)
print a,"->>",c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
2015-11-28
L = []
a=1
while True:
L.append(a*a)
a=a+1
if a > 100:
break
print sum(L)
a=1
while True:
L.append(a*a)
a=a+1
if a > 100:
break
print sum(L)
2015-11-28
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for ll in L:
if ll in s:
s.remove(ll)
else:
s.add(ll)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for ll in L:
if ll in s:
s.remove(ll)
else:
s.add(ll)
print s
2015-11-28
# coding= utf-8
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x,v in s:
print x,":",v
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x,v in s:
print x,":",v
2015-11-28
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
score =85
for name in d:
if d[name] ==score:
print name
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
score =85
for name in d:
if d[name] ==score:
print name
2015-11-28