sum = 0
x = 1
n = 1
while True:
x=x+2**n
n=n+1
sum=sum+x
if n>=19:
break
print sum
x = 1
n = 1
while True:
x=x+2**n
n=n+1
sum=sum+x
if n>=19:
break
print sum
2015-04-27
def average(*args):
a=len(args)
if a ==0:
return 0
else:
return float(sum(args))/a
a=len(args)
if a ==0:
return 0
else:
return float(sum(args))/a
2015-04-27
def average(*args):
if len(args) == 0:
return 0.0
else:
b = 0
for i in args:
b = b + i
return float(b)/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args) == 0:
return 0.0
else:
b = 0
for i in args:
b = b + i
return float(b)/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-04-27
@luoqing1999
将 n-1 个盘子从 a 经过 c 搬运到 b,即move(n-1, a, c, b);
将 n-1 个盘子从 b 经过 a 搬运到 c,即move(n-1, b, a, c);
这两步虽然看能勉强理解,但是自己还是写不出。
将 n-1 个盘子从 a 经过 c 搬运到 b,即move(n-1, a, c, b);
将 n-1 个盘子从 b 经过 a 搬运到 c,即move(n-1, b, a, c);
这两步虽然看能勉强理解,但是自己还是写不出。
2015-04-27
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-26
L = ['Adam', '95.5', 'Lisa', '85', 'Bart', '59']
print L
print L
2015-04-26
L = ['Adam', 'Lisa', 'Bart']
L.insert(-1, 'Paul')
print L
L.insert(-1, 'Paul')
print L
2015-04-26