What's the method for figuring out question 2 on module 3 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's the method for figuring out question 2 on module 3

I'm genuinely stuck with no clue of how to do this question. I have a feeling there's a bug in this question cause I've tried a lot of combination of answer and none have worked. If someone could at least give me a hint for this It would be appreciated. P.S. I have no more xp to get a hint since I wasted it not knowing how valuable it was. The question is: Rearrange the code to define a function that calculates the sum of all numbers from 0 to its argument The available lines to move around are: res=0 return res for i in range(x): res+=I def sum(x)

5th Sep 2016, 6:02 PM
Jian Xin Lim
12 Answers
+ 5
This is ans : def sum(x): res = 0 for i in range(x): res += i return res
2nd May 2017, 2:29 PM
Mahnoor Shahzad
Mahnoor Shahzad - avatar
+ 3
The question is: Rearrange the code to define a function that calculates the sum of all numbers from 0 to its argument The available lines to move around are: res=0 return res for i in range(x): res+=I def sum(x)
5th Sep 2016, 6:04 PM
Jian Xin Lim
+ 2
Thank You for the answer. I've now finished the question
5th Sep 2016, 6:24 PM
Jian Xin Lim
0
could you please post the full question to get a hint...
2nd Sep 2016, 11:33 PM
Amarie
0
You can solve this by defining the function, setting res = 0 and then looping from 0 to x while adding loop counter every time in the res variable
5th Sep 2016, 6:19 PM
Govind Sharma
Govind Sharma - avatar
0
i want the exact answer for this question
18th May 2018, 4:12 PM
Sreegayathri
Sreegayathri  - avatar
0
Tell me frnds that exact answer when you know about it
6th Jan 2019, 2:33 PM
Amaravathi Anilkumar
Amaravathi Anilkumar - avatar
0
Answer: def sum(x): res = 0 for i in range(x): res += i return res
27th May 2019, 4:29 PM
vivek barnwal
0
Thanks
22nd Nov 2019, 10:26 AM
MBoadu32
MBoadu32 - avatar
0
Answer: def sum(x): res = 0 for i in range(x): res += i return res
23rd Feb 2020, 4:40 AM
VISHNUPRIYAN V
VISHNUPRIYAN V - avatar
- 1
no seeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
1st Feb 2019, 12:55 AM
Emilie Ivonne Donis Castañeda
Emilie Ivonne Donis Castañeda - avatar
- 1
Ha@aaaaaaaaaa
1st Feb 2019, 1:28 AM
Amaravathi Anilkumar
Amaravathi Anilkumar - avatar