Never gonna give u up!? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Never gonna give u up!?

So I am trying to add 1 to the value of the variable "Start" in a for loop but It's not giving me the desired result. In the TwoSum program, you gotta input a target value and a list of numbers. Where the sum of any two numbers will be == target. If the condition is true then it will print the indices of the number in the list else it's gonna pass https://code.sololearn.com/cfYQnI9qjTf2/?ref=app

23rd Oct 2022, 5:13 PM
Kaushik
Kaushik - avatar
3 Answers
+ 2
What is your expected output actually?
23rd Oct 2022, 6:17 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 I want the start value which is initially 0 to add 1 in the for loop You may see that at the end of the for loop I added Start+=1 but it's not getting added up
24th Oct 2022, 5:36 AM
Kaushik
Kaushik - avatar
0
Kaushik Your condition : if (list[start] + list[index]) == target: list[0] + list[2] == 7 : is 4+3 == 7 True So at first iteration it's breaking loop because you have break in if block. It won't going to execute start+=1 .. check with sample list [ 4,3,2 ] ., you can see change.
24th Oct 2022, 12:09 PM
Jayakrishna 🇮🇳