L=[]
for x in range(1,10):
for y in range(0,10):
z=x*100+y*10+x
L.append(z)
print L
for x in range(1,10):
for y in range(0,10):
z=x*100+y*10+x
L.append(z)
print L
2020-06-21
print [m*100+n*10+k for m in range(1,10) for n in range(0,10) for k in range(0,10) if m==k]
2020-06-21
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
n = 0
sum = 0.0
for v in d.itervalues() :
sum = sum + v
n = n + 1
print sum * 1.0 / n
n = 0
sum = 0.0
for v in d.itervalues() :
sum = sum + v
n = n + 1
print sum * 1.0 / n
2020-06-20
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2020-06-19
1.因为a为非空字符串,所以看成True,在or关系中,则结果为True,返回a;
2.因为b为空字符串,所以看成False,在or关系中,返回结果取决于另外一个字符串,即‘world’,非空,则结果为True,返回‘wrold’
2.因为b为空字符串,所以看成False,在or关系中,返回结果取决于另外一个字符串,即‘world’,非空,则结果为True,返回‘wrold’
2020-06-19
def firstCharUpper(s):
a=s[0:1].upper()
b=s[1:]
return a+b
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
a=s[0:1].upper()
b=s[1:]
return a+b
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2020-06-18
def average(*args):
if len(args) ==0:
return 0.0
else:
sum = 0
n =0
for s in args:
sum = sum +s
n = len(args)
return sum * 1.0 / n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args) ==0:
return 0.0
else:
sum = 0
n =0
for s in args:
sum = sum +s
n = len(args)
return sum * 1.0 / n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2020-06-18
def greet(x='world'):
print 'Hello,',x,'.'
greet()
greet('Bart')
print 'Hello,',x,'.'
greet()
greet('Bart')
2020-06-18
def move(n, a, b, c):
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)
# print a,'-->',b
print a,'-->',c
move(n-1,b,a,c)
# a-->b a-->c b-->c
move(4, 'A', 'B', 'C')
做不出来的时候好难,做出来理解了就简单了。
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)
# print a,'-->',b
print a,'-->',c
move(n-1,b,a,c)
# a-->b a-->c b-->c
move(4, 'A', 'B', 'C')
做不出来的时候好难,做出来理解了就简单了。
2020-06-18