The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Two sum code

Two sum code

Super Learner
0
Votes
0
Answer

why the code do not need ‘else:’ ??and why ‘return False’  command need to  be placed exactly at that position as the arrow indicate  to run properly??
def Twosum(a, target):
            for i in range(len(a)):
                   for j in range(i+1, len(a)):
                       if a[i]+a[j]==target:
                           print(a[i], a[j])
                           print(a.index(a[i]), a.index(a[j]))
                           return True
——->  return False
print(Twosum(a, target))
 

No answers so far.