Pyhon函数

import time
#
# for i in range(1,10):
#     j=1
#     for j in range(1,i+1):
#         print(f"{i}x{j}={i*j}  " ,end='')
#     print()
#复用,代码,精简,复用度高


def j99(n=1,max=10):      
    for i in range(n,max):
        j=i
        for j in range(i,max):
            print(f"{i}x{j}={i*j} " ,end='')
        print()
    print("*"*50)
    print()
    




# j99()
# j99(2,15)
# j99(3)
# j99(4)
# j99(5)
# j99(6)
# j99(7)
# j99(8)
# j99(9)


# v=lambda a,b,c:a*b*c
# print(v(4,5,6))


#1,2,3,5,8,13,21,34,55
# sn=Sn-1+Sn-2
# s1=1
# s2=2
# s(50)
def gttime():
    t=time.gmtime()
    return time.strftime("%Y-%m-%d %H:%M:%S",t)


def dg(n):
    if(n==1):
        return 1
    elif(n==2):
        return 2
    else:
        return dg(n-1)+dg(n-2)
    
    


def dglist(n):
    list=[]
    list.append(1)
    list.append(2)
    if n>=3:
         for i in range(3,n+1):
              list.append(i)
              list[i-1]=list[i-2]+list[i-3]
            #   print()    
    return list[n-1]

print(f"这是list优化算法,{dglist(40)},\n时间" )
print(gttime())

print(f"这是递归算法,{dg(40)} ,时间" )

print(gttime())




list去重方法

你可能感兴趣的:(windows,python,开发语言)