函数嵌套(闭包)、阶乘、斐波那数列知识


#闭包,函数嵌套函数时,返回值用的是内层函数

'''
def f1(m):
def2(n):
return m*n
return f2
'''
'''
#阶乘
def factorial(n):
if n==1:
return 1
else:
return factorial(n-1)*n

print(factorial(100))
'''

'''
from tkinter import *

root=Tk()
root.geometry('400x400+300+100')

def click():
print('我被调用了...')
Button(root,text='点我',command=click,bg='red').pack(fill=X,aexpand=1)

root.mainloop()

'''
#斐波那契数列
def f(n):
if n==1 or n==2:
return 1
else:
return f(n-2) + f(n-1)

#输出100以内的所有素数,素数之间以一个空格区分
S=[]
for i in 101:
for n in 101:
if i%n ==1 or i%n==i:
return S.append(i)
print(S)

原文地址:https://www.cnblogs.com/kindnull/p/6736302.html