最大公约数最小公倍数
x=eval(input("please enter a num as x:"))
y=eval(input("please enter a num as y:"))
mul=x*y
while x%y!=0:
x,y=y,x%y
print("max same is:",y)
min=mul//y
print("min same is:",min)
统计各种字符个数
s=input("please enter a text:")
alpha,digit,space,other=0,0,0,0
for i in s:
if i.isalpha():
alpha+=1
elif i.isdigit():
digit+=1
elif i.isspace():
space+=1
else :
other+=1
print("""字母的个数为:{},数字的个数为:{}
,空格的个数为:{},其它的个数为:{}""".format(alpha,digit,space,other))
函数类型
def add1(a,b):
return a+b
def add2(a,b,c):
return a+b+c
def text():
pass
print(type(text()))
print(type(add1))
print(type(add2(1,2,3)))
函数定义不一定在调用之前: 一般认为函数定义必须在函数调用之前,但如果函数A调用函数B,那么函数B的定义可以放在函数B的调用之后
def add3(n):
n=add2(n)
return n+1
def add2(n):
return n+2
print(add3(1))
值传递和地址传递(list列表)
斐波那契数列(递归)
def feibo(n):
if n==1 or n==2:
return 1
else:
return feibo(n-1)+feibo(n-2)
x=eval(input("please enter the num you want to search:"))
print("the num's number is:",feibo(x))