智慧职教: 求1+2+……+10的程序如下,请完善: sum = 0 for i in range(11): sum = sum+ print(sum)
举一反三
- def func(): global sum sum=0 print(sum) for i in range(5): sum+=1 print(sum) func() print(sum)
- 如下程序的运行结果是?sum=0 for i in range(2,101,2): sum=sum+i print(sum)
- 下列程序的输出结果是:sum = 0 def sum(i1, i2): result = 0 for i in range(i1, i2 + 1): result += i return result print sum(1, 10)
- 1. 以下求10以内的所有奇数之和的值是() sum = 0 i= 1 while i < 10: if i % 2 !=0: sum += i i ++ print (sum)
- 以下for语句中,不能完成1~10的累加功能的是A.for i in range(10,0): sum += iB.for i in range(1, 11): sum += iC.for i in range(10, 0, -1): sum += iD.for i in (10, 9, 8, 7, 6, 5, 4, 3, 2, 1): sum += i