def sum_func(*args):
sm = 0
for i in args:
sm += i
return sm
print(sum_func(1,2,3,7,4,5,6))
以上程序执行结果为
sm = 0
for i in args:
sm += i
return sm
print(sum_func(1,2,3,7,4,5,6))
以上程序执行结果为
28
举一反三
- def func(): global sum sum=0 print(sum) for i in range(5): sum+=1 print(sum) func() print(sum)
- 自定义函数,计算不定长参数累加和。 (1) (2)((3)): (4) for i in args: s(5)i print(s) sum(1,2,3,4,5,6,7,8,9)
- 下列程序的输出结果是:sum = 0 def sum(i1, i2): result = 0 for i in range(i1, i2 + 1): result += i return result print sum(1, 10)
- ls = ['I','LOVE'] def func(a): ls = [] ls.append(a) return func('WTU') print(ls)
- 请阅读下面的程序,sum的值为()publicclassTest{publicstaticvoidmain(String[]args){intsum=0;for(inti=1;i=100;i++){if(i%2==1){continue;}sum+=i;}System.out.println(sum=+sum);}}
内容
- 0
下面代码的输出结果为( ) for i in range(1, 7): if i % 2 == 0: print(i, end=" ") A: 1 2 3 4 5 6 7 B: 1 2 3 4 5 6 C: 2 4 6 7 D: 2 4 6
- 1
下列程序执行后,sum的结果是________。Dim sum As IntegerFor i = 1 To 4 Step 2 For j = 1 To i Step 2 sum += j NextNext A: 6 B: 9 C: 5 D: 7
- 2
已知函数定义def func(* p) :return sum(p),那么表达式func(1,2,3)的值为
- 3
下列程序的执行结果是( ).for i in range(2): print(i,end=' ' )for I in range(4,6): print(I,end=' ' ) A: 2 4 6 B: 0 1 2 4 5 6 C: 0 1 0 1 2 3 D: 0 1 4 5
- 4
下列函数int func ( int n ){ int i = 0, sum = 0;while ( sum <; n ) sum += ++i;return i;}的时间复杂度是 A: O(nlogn) B: O(n) C: O(n1/2) D: O(logn)