马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这个汉诺塔总是听的懵懵的,能理解大致的方法和逻辑 ##################################P50
def funa():
print('ASDFGH')
def funb():
funa()
funb()
def func(i):
if i>0:
print('ASDFG')
i=i-1
func(i)
func(5)
def fund(i):
if i >0:
j=1
for (i) in range(i):
# print(i)
j=j*(i+1)
print(j)
return j
ss=fund(5)
def fune(i):
if i>0 and i==1:
return 1
else:
return i*fune(i-1)
aa=fune(6)
print(aa)
def fibiter(n):
a=1
b=1
c=1
while n>2:
c=a+b
a=b
b=c
n=n-1
print(c)
return c
fibiter(12)
def fibitera(n):
if n==1 or n==2:
return 1
else:
return fibitera(n-1)+fibitera(n-2)
aa=fibitera(12)
print(aa)
##################################P51
def hanoi(n,x,y,z):
if n==1:
print(x,'-->',z)
else:
hanoi(n-1, x, z, y)
print(x, '-->', z)
hanoi(n - 1, y, x, z)
# n=int(input('''汉诺塔层数:'''))
n=3
hanoi(n,'A','B','C')
##################################P52
def exchange(dollar,rate=6.32):
"""
功能:汇率转换
:param dollar: 美元数量
:param rate: 汇率
:return: 人民币数量
"""
print(dollar*rate)
return dollar*rate
exchange(20)
def times(s:str,n:int) -> str:
print(s*n)
return s*n
times('sc',5)
def times(s:list,n:int=3) -> list:
print(s*n)
return s*n
times([1,2,3],5)
def times(s:dict[str,int],n:int=3) -> list:
print(list(s.keys())*n)
return list(s.keys())*n
times({'A':1,'B':2,'C':3},5)
print(times.__name__)
print(times.__annotations__)
print(exchange.__doc__)
##################################P53
def add(x,y):
print(x+y)
return x+y
import functools
functools.reduce(add,[1,2,3,4,5])
print(functools.reduce(lambda x,y:x*y,range(1,11)))
square=functools.partial(pow,exp=2)
print(square(2))
cube=functools.partial(pow,exp=3)
print(cube(2))
|