python函数作业1

1.写函数,接收n个数字,求这些数字的和

# 函数名不定义为sum,避免与内置函数冲突
def sum_func(*args):
    total = 0
    for i in args:
        total += i
    return total


print(sum_func(1, 3, 4, 33, 44, 66))

2.代码中打印出来的a,b,c分别是什么?为什么?

a=10
b=20
def test5(a,b):
    print(a,b)
c = test5(b,a)
#此处的b,a是常量不是变量
#上面语句的含义:先函数运行完,再把返回值赋给c,因为test5函数没返回值,故c为None
print(c)
#20 10
#None

代码执行过程

3.读代码,回答:代码中,打印出来的值a,b,c分别是什么?为什么?

a=10
b=20
def test5(a,b):
    a=3
    b=5
    print(a,b)
c = test5(b,a)
print(c)

代码执行过程

 

posted @ 2018-09-18 21:58  zwz123  阅读(270)  评论(0)    收藏  举报