Help me to arrange this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Help me to arrange this code

Hi guys help me to arrange this code res = 0 return res for i in range(x): def sum(x): res += i

7th Feb 2022, 3:42 PM
Abdulatif Mohamednor Mohamed
Abdulatif Mohamednor Mohamed - avatar
6 Answers
+ 2
Dion shaddy I am not understanding what u talking about. Please explain what u trying to say .
8th Feb 2022, 2:50 PM
Abdulatif Mohamednor Mohamed
Abdulatif Mohamednor Mohamed - avatar
+ 1
What is your try? Pls mention your trouble in getting it right?
7th Feb 2022, 3:46 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna It's model 6 Guiz ( arrange ) I try different way but I didn't get right arrangement
7th Feb 2022, 3:54 PM
Abdulatif Mohamednor Mohamed
Abdulatif Mohamednor Mohamed - avatar
+ 1
Actually this is one of the quizzes where we drag those draggable lines and arrange them to make a meaningfully code segment right? Don't just try different combinations, find the correct answer and try that. The correct answer to this question is: def sum(x): res=0 for i in range(x): res+=i return res First, a variable "res" is created to hold the sum of the numbers, with initial value 0. Then a loop runs from 0 to x and adds it to the variable "res". Finally "res" is returned. As simple as it sounds
7th Feb 2022, 4:03 PM
Rishi
Rishi - avatar
+ 1
Rishi tank you it is worked
7th Feb 2022, 4:26 PM
Abdulatif Mohamednor Mohamed
Abdulatif Mohamednor Mohamed - avatar
+ 1
Dion Shaddy what are you trying to say? 😗
8th Feb 2022, 2:25 PM
Rishi
Rishi - avatar