作业:
9*9乘法表格式:
1 * 1 = 1
2 * 1 = 2 2 * 2 = 4
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
........
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 ......................................................................9 * 9 = 81
1.使用for循环打印9*9乘法表
for i in range(1, 10): for j in range(1, i+1): print(i, "*", j, '=', j * i, end='\t') print('')
2.使用while循环打印9*9乘法表
i = 1 while 9 >= i >= 1: j = 1 while i >= j >= 1: print(i, "*", j, '=', j * i, end='\t') j += 1 i += 1 print('')
3.选做:使用while单层循环打印9*9乘法表
i = 1 j = 1 while i <= 9: if j <= i: print(i, '*', j, '=', i * j, end='\t') j += 1 else: j = 1 i += 1 print('')
4.定义函数:
定义一个函数:函数的位置参数以及关键字参数的个数不确定
def test_data(*args, **kwargs): print(args, kwargs) test_data(1, num='song')
5.定义一个函数:函数的前三个参数必须以位置参数形式参数传递,后边两个参数必须以关键字形式进行传递
def test_data2(arg1, arg2, arg3, /, *, arg4, arg5, arg6): print(arg1, arg2, arg3, arg4, arg5, arg6) test_data2(1, 2, 3, arg4=4, arg5=5, arg6=6)