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
3 Antworten
+ 2
What is your expected output actually?
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
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.