def firstCharUpper(s):
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2016-08-05
def average(*args):
l=len(args)
if l==0:
return 0.0
else:
return sum(args)*1.0/l
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
l=len(args)
if l==0:
return 0.0
else:
return sum(args)*1.0/l
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2016-08-05
def greet(a='world'):
print 'Hello,',a,'.'
greet()
greet('Bart')
print 'Hello,',a,'.'
greet()
greet('Bart')
2016-08-05
def move(n, a, b, c):
if n == 1:
print a,'-->',c#打印
return
else:
move(n-1, a, c, b)#将a上n-1个移到b上
move(1, a, b, c)#将a上第n个移到c上
move(n-1, b, a, c)#将b上的n-1个移到c上
if n == 1:
print a,'-->',c#打印
return
else:
move(n-1, a, c, b)#将a上n-1个移到b上
move(1, a, b, c)#将a上第n个移到c上
move(n-1, b, a, c)#将b上的n-1个移到c上
2016-08-05
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d.get('Adam')
print 'Lisa:',d.get('Lisa')
print 'Bart:',d.get('Bart')
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d.get('Adam')
print 'Lisa:',d.get('Lisa')
print 'Bart:',d.get('Bart')
2016-08-05
L = []
n = 1
while n <= 100:
L.append(n * n);
n = n+1
print sum(L)
n = 1
while n <= 100:
L.append(n * n);
n = n+1
print sum(L)
2016-08-04
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for l in L:
if l in s:
s.remove(l)
else:
s.add(l)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for l in L:
if l in s:
s.remove(l)
else:
s.add(l)
print s
2016-08-04