+ 1
Functions and Modules: Module Quiz 3: Questions two
It says, ¨Rearrange the code to define a function that calculates the sum of all the numbers from 0 to its argument.¨ Then here are the choices: A) res + = i B) def sum (x): C) return res D) res = 0 E) for i in range(x): I clicked all of them and every single one was wrong.
1 Answer
+ 7
def sum (x):
res = 0
for i in range(x):
res + = i
return res
It sums numbers from 0 to x-1