python day10作业答案

时间:2022-11-30 22:39:17
2.def func(*args):
    sum = 0
    for i in  args:
        sum=sum+int(i)
    return sum
a=func(2,3,9,6,8)
print(a)
3.
a=10
b=20
def test5(a,b):
    print(a,b)
c=test5(b,a)
4.
a=10
b=20
def test5(a,b):
    a=3
    b=5
print(a,b)
c=test5(b,a)
print(c)
5.
def func(*args):
    return args
a=func(*[1,2,3],*(22,33))
print(a)
6.
def func(**args):
    return args
a=func(**{'name':'alex'},**{'fg':"dadf"})
print(a)
7.
7.1
a=2
def wra():
    print(a)
wra()
7.2
a=2
def wra():
    a+=1#不能让a重新赋值
print(a)
wra()
7.3
def wra():
    a=1
    def innner():
        print(a)
    innner()
wra()
7.4
def wra():
    a=1
    def innner():
        a+=1
        print(a)
    innner()
wra()
8.
def func(*args):
    for i in range(len(args)-1):
        if args[i]>args[i+1]:
            return args[i+1]
        else:
            return args[i]
a=func(25,63)
print(a)
9.
def func(args):
    a='_'.join(args)
    return a
a=func(['1','水电费','apple'])
print(a)
10
def func(*lst):
    dic={}
    dic['max']=max(lst)
    dic['min'] = min(lst)
    return dic
a=func(2,5,9,8,6,3)
print(a)
11.
def func(num):
    sum=1
    for i in range(1,num+1):
        sum=sum*i
    return sum
a=func(3)
print(a)
12.
def func():
    lst = []
    for i in range(1,53):
        a=('草花',i)
        b=('红心',i)
        c=('黑桃',i)
        d=('方块',i)
        lst.append(a)
        lst.append(b)
        lst.append(c)
        lst.append(d)

    return lst
a=func()
print(a)