Functions and Modules: Module Quiz 3: Questions two | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

12th Apr 2019, 2:18 PM
Raven Gerard
Raven Gerard - avatar
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
12th Apr 2019, 2:45 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar