Python 3 - Modules Quiz - Question #5
The answer to this quiz question is "6." However, I cannot seem to figure out why that is so... We define the function to take the argument "x." Then we set "res" to mean zero. Next, for "i" in a range of this same variable "x," we will add "res," which is zero. This literally doesn't seem to add anything. (Zero plus any number results in the original number--the zero principle of addition, right?) Then it says to "return 'res'," which makes "res" the new number for "i?" Finally, the last line runs through the program using 4 as the argument. To "i" in a range of 4, add 0. That gives us 4, no? But the answer is 6....Hmm. _____ "What is the output of this code?" def func(x): res = 0 for i in range(x): res += i return res print(func(4)) ____