0

What is error in it??

class Plan: r = [] re = [] def __init__(self,arr): self.arr=arr def func(self): for j in range(len(self.arr)): for k in range(j,len(self.arr)): Plan.r.append(sum(self.arr[j:k+1])) for p in Plan.r: if p[::-1]==p: Plan.re.append(p) return Plan.re ab = Plan(list(map(int,input("Enter the values with the spaces:").split(" ")))) print(ab.func()) In this i need to print the minimum sum of two numbers in a arr

3rd Jan 2022, 7:48 AM
Ravi King
8 Answers
+ 10
Ravi King , you mentioned that you are going to find the *minimum sum of 2 numbers in an array*. so this means for me that we have to find the *two smallest numbers of the array* and build the sum of them. i am just wondering if you are not allowed to use built-in functions like sorted() to do this task. by sorting the array (list) and using a slice for the *first 2 elements*, we can get less lines of code to accomplish this task. using this list: [3 7 -8 -12 9], *- 20* would be the minimum sum. or did i get you wrong?
3rd Jan 2022, 11:44 AM
Lothar
Lothar - avatar
+ 9
Ravi King , so you could do : â–Șfind min element in list and store it in var â–Șremove the min element from the list â–Șfind again min element in the list (which is the second smallest number of the original list) and store it in var2 â–Șsum var1 and var2
3rd Jan 2022, 12:08 PM
Lothar
Lothar - avatar
+ 6
Ravi King , are you allowed to use min() function?
3rd Jan 2022, 11:59 AM
Lothar
Lothar - avatar
+ 5
The second for loop is using r in a way that implies it should be an array of iterables. But what I gather from the code leading up to this point, r is an array of single values. Ravi King can you explain this? for p in Plan.r: if p[::-1]==p: Plan.re.append(p)
3rd Jan 2022, 11:19 AM
Brian
Brian - avatar
+ 3
Please give more info. We don't know what the program is meant for, what you're trying to do with it, what the input may be, what the expected output for that input is, what r and re are there for, and please copy and paste code in the playground so we can run it and help faster.
3rd Jan 2022, 9:23 AM
Slick
Slick - avatar
+ 1
Thanks
3rd Jan 2022, 12:19 PM
Ravi King
0
In this question we are not allowed to use the sort() function
3rd Jan 2022, 11:53 AM
Ravi King
0
Yes
3rd Jan 2022, 11:59 AM
Ravi King