裴波那契: def fun(arg1,arg2,stop): if arg1==0: print(‘%s\n%s‘%(arg1,arg2)) arg3=arg1+arg2 print(arg3) if arg3<stop: fun(arg2,arg3,stop) fun(0,1,100)
打印结果:
0
1
1
2
3
5
8
13
21
34
55
89
144
取中间值的算法
suanfa(a,b): mid=((a)/) (a)>: a[mid]>b: suanfa(a[:mid],b) a[mid]<b: suanfa(a[mid:],b) : (,a[mid]) : () data=((,)) suanfa(data,)
打印结果
>>you 5
90度翻转算法1:
=[[col col ()]row ()] ()
90度翻转算法2:
=[[col col ()]row ()] () r_i,row (): c_i (r_i,(row)): tmp=[c_i][r_i] [c_i][r_i]=row[c_i] [r_i][c_i]=tmp r :(r)
打印结果:
[[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]
[0, 0, 0, 0]
[1, 1, 1, 1]
[2, 2, 2, 2]
[3, 3, 3, 3]
时间: 2024-10-10 01:10:19