完成 n 个盘子从 a 经过 b 到 c 的搬运只需要3步,第一步:将 n-1 个盘子从 a 经过 c 搬运到 b,即move(n-1, a, c, b); 第二步:将 第 n 个盘子 从 a 移到 c,即 print a, '-->', c; 第三步: 将 n-1个盘子从 b 经过 a 搬运到 c,即move(n-1, b, a, c);完事, 至于这 n-1 个盘子是怎么搬运的呢,他又自己进入了下一个循环
2016-06-20
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key, ': ', d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key, ': ', d[key]
2016-06-20
import math
def quadratic_equation(a, b, c):
y=math.sqrt(b*b-4*a*c)
x1 = 0.5*a*(-b+y)
x2 = 0.5*a*(-b-y)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
y=math.sqrt(b*b-4*a*c)
x1 = 0.5*a*(-b+y)
x2 = 0.5*a*(-b-y)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2016-06-20
print 'hello,python'
print 'hello', ',', 'python'
print 'hello', ',', 'python'
2016-06-20
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')
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')
2016-06-20
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(-2)
L.pop(-1)
print L
L.pop(-2)
L.pop(-1)
print L
2016-06-20