x1 = 1
d = 3
n = 100
x100 = 1+(n-1)*d
s = (x1+x100) * n / 2
print s
宝宝数学渣
d = 3
n = 100
x100 = 1+(n-1)*d
s = (x1+x100) * n / 2
print s
宝宝数学渣
2015-12-29
L = ['Bart', 'Lisa', 'Adam']
print L
print L
2015-12-29
print [a * 100 + b * 10 + c for a in range(1, 10) for b in range(0, 10) for c in range(0, 10) if a == c]
2015-12-29
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')
2015-12-29
def average(*args):
if len(args) == 0:
return 0.0
sum = 0.0
for a in args:
sum += a
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args) == 0:
return 0.0
sum = 0.0
for a in args:
sum += a
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-12-29
def greet(prin = 'world'):
print 'Hello,',prin,'.'
greet()
greet('Bart')
print 'Hello,',prin,'.'
greet()
greet('Bart')
2015-12-29
def move(n, a, b, c):
if n == 1:
print a,'-->',c
else:
move(n - 1, a, c, b)
move(1, a, b, c)
move(n -1, b, a, c)
move(4, 'A', 'B', 'C')
if n == 1:
print a,'-->',c
else:
move(n - 1, a, c, b)
move(1, a, b, c)
move(n -1, b, a, c)
move(4, 'A', 'B', 'C')
2015-12-29
print [a*100+b*10+c for a in range(1,10) for b in range(0,10) for c in range(0,10) if a==c]
2015-12-28