- 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)
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.
+ 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")
+ 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
+ 1
Shahir Could you please give an example of an input and the corresponding output?
+ 1
Thanks it works!