第四次作业

1.使用for循环打印9*9乘法表

for i in range(1, 10):
    for j in range(1, i + 1):
        print(i, "*", j, "=", i * j, end="\t")
    print()


2.使用while循环打印9*9乘法表

i = 1
j = 1
while i <= 9:
    j = 1
    while j <= i:
        print(i, "*", j, "=", i * j, end="\t")
        j = j + 1
    i = 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 = j + 1
    else:
        print()
        i = i + 1
        j = 1


4.定义函数:
定义一个函数:函数的位置参数以及关键字参数的个数不确定

def mv_func(*args, **kwargs):
    print(args, kwargs)


mv_func(1, 2, 3)
mv_func(arg1=1, arg2=2, arg3=3)
mv_func(1, 2, 3, arg4=4, arg5=5, arg6=6)
print(1, 2, 3, 4, 5)


定义一个函数:函数的前三个参数必须以位置参数形式参数传递,后边两个参数必须以关键字形式进行传递

def my_func3(arg1, arg2, arg3, /, *, arg4, arg5):
    print(arg1, arg2, arg3, arg4, arg5)


my_func3(1, 2, 3, arg4=4, arg5=5)

  • 11
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值