- 3

Help me to fix the error?

a = [] b = input().split(" ") u = int(input()) for i in b: a.append(int(i)) for j in range(len(a)): for o in range(j+1,len(a)): for p in range(o+1,len(a)): if a[j]+a[o]+a[p] ==u: print(j,o,p)

8th Aug 2021, 12:43 PM
Shahir
Shahir - avatar
5 Réponses
+ 2
A lot of problems here but first: Before asking a question give a description of what you want to achieve. It's really difficult to understand anything from the code here.
8th Aug 2021, 1:07 PM
Sanjay
+ 2
Try this a = [] b = input().split(" ") u = int(input()) found_solution = False for i in b: a.append(int(i)) for j in range(len(a)): for o in range(j+1,len(a)): for p in range(o+1,len(a)): if a[j]+a[o]+a[p] == u: print(j,o,p) found_solution = True if not found_solution: print("There is no solutions")
8th Aug 2021, 1:22 PM
Sanjay
+ 1
Task is to find the sum of any three numbers in an array such that there sum is equal to input that given by the user
8th Aug 2021, 1:12 PM
Shahir
Shahir - avatar
+ 1
Shahir Could you please give an example of an input and the corresponding output?
8th Aug 2021, 6:36 PM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Thanks it works!
8th Aug 2021, 11:58 PM
Shahir
Shahir - avatar