本文转载:https://xiaochuhe.blog.csdn.net/article/details/122539441
一、知识点31~35
#31.枚举排序 0,1,2…
tuple = ('a','b','c','d')
for i,j in enumerate(tuple):
print (i,j)
#print ('1\n2')
#print ('1\t2')
#32.9*9乘法表练习
for i in range(1,10):
print ("\t")
for j in range (1,1+i):
#result = i * j
print ("%d * %d = %d"%(i,j,i*j),end= " ")
#33.函数的定义
from colorama import Fore
def chuhe():
print ('\n_________________')
print (Fore.RED+"这是一个函数")
chuhe()#函数的调用
#34.函数带参数的定义
def sum(a,b):
c = a + b
print (c)
sum(1,2)#输出3
#35.返回值计算结果
def sum(a,b):
return a + b
vule = sum(1,2)#print(sum(1,2))
print (vule)
输出结果:
二、知识点36~40
#36.返回多个结果,逗号分割
def sum(a,b):
shang = a/b
yushan = a%b
return (shang,yushan)
shang,yushang=sum(2,1)
print (shang,yushang)
#37.练习:自动输入数字,输出特定的长度
def length():
a = int(input("数字:"))
print ('-'*a)
length()
#38.求三数字平均数
def sum():
a = int(input('第一个数:'))
b = int(input('第二个数:'))
c = int(input('第三个数:'))
add = (a + b + c) / 3
print (add)
sum()
#39.输出给定长度为10次数练习
def sum():
print ('-'*10)
def chuhe(m):
i = 0
while i<m:
sum()
i +=1
sum()
chuhe(int(input("请输出你要给定长度为10的次数:")))
#40.全局遍历与局部变量,局部变量调用全局变量
a = 100
def sum():
global a
print (a)#输出100
a = 500
print("%d" % a) # 输出500
print (a)#输出500
sum()
输出结果: