1.中位数函数
def bigger(a,b):
if a > b:
return a
else:
return b
def biggest(a,b,c):
return bigger(a,bigger(b,c))
def median(a,b,c):
big = biggest(a,b,c)
if big == a:
return bigger(b,c)
if big == b:
return bigger(a,c)
else:
return bigger(a,b)
2. find_last 函数
def find_last(s,t):
last_pos = -1
while True:
pos = s.find(t, last_pos + 1)
if pos == -1:
return last_pos
last_pos = pos
3. 乘法表
def print_multiplication_table(n):
i = 1
while i <= n:
j = 1
while j <= n:
print str(i) + ' * ' + str(j) + ' = ' + str(i * j)
j = j + 1
i = i + 1
输出结果:
#print_multiplication_table(2)
#>>> 1 * 1 = 1
#>>> 1 * 2 = 2
#>>> 2 * 1 = 2
#>>> 2 * 2 = 4