以下代码的运行结果为
def calculate(number):
result = 0
i = 1
while i <= number:
result = result + i
i += 1
return result
result = calculate(100)
print('1~100的累积和为:', result)
def calculate(number):
result = 0
i = 1
while i <= number:
result = result + i
i += 1
return result
result = calculate(100)
print('1~100的累积和为:', result)
举一反三
- 以下代码中calculate()函数属于哪个分类 def calculate(number): result = 0 i = 1 while i
- 中国大学MOOC: 以下代码运行后,result的值为( )var result = 0;for (var i = 1; i <= 10; i++) {result = result * i}
- 下列程序的输出结果是:sum = 0 def sum(i1, i2): result = 0 for i in range(i1, i2 + 1): result += i return result print sum(1, 10)
- 下列语句的执行结果是: result = 0 i = 1 while result <; 10: result += i i += 1 if i >; 2: break print(result) A: 3 B: 5 C: 7 D: 10
- 以下代码运行后,result的值为( )var result = 0; for (var i = 1; i <;= 10;i++) { result = result * i } A: 0 B: 1 C: 9的阶乘 D: 10的阶乘