+ 15

Why it is showing error?[solved]

data = [7, 5, 6.9, 1, 8, 42, 33, 128, 1024, 2, 8, 11, 0.4, 1024, 66, 809, 11, 8.9, 1.1, 3.42, 9, 100, 444, 78] data.sort() sum=0 for i in range(1,(len(data)-1)): sum+=data[i] print(sum)

26th Aug 2021, 7:01 AM
Atul [Inactive]
34 Respuestas
+ 7
#Try this data = [7, 5, 6.9, 1, 8, 42, 33, 128, 1024, 2, 8, 11, 0.4, 1024, 66, 809, 11, 8.9, 1.1, 3.42, 9, 100, 444, 78] data.remove(max(data)) data.remove(min(data)) print(sum(list(data)))
26th Aug 2021, 7:52 AM
Simba
Simba - avatar
+ 5
It's working just fine for me.
26th Aug 2021, 7:04 AM
Calvin Thomas
Calvin Thomas - avatar
+ 3
I do not know the task text, and cannot understand why you sort the array and why the range is smaller. But you can try this: data = [7, 5, 6.9, 1, 8, 42, 33, 128, 1024, 2, 8, 11, 0.4, 1024, 66, 809, 11, 8.9, 1.1, 3.42, 9, 100, 444, 78] sum=0 for i in range((len(data)): sum+=data[i] print(sum)
26th Aug 2021, 7:15 AM
JaScript
JaScript - avatar
+ 2
No it's a code coach
26th Aug 2021, 7:06 AM
Atul [Inactive]
+ 2
Atul [Inactive] Here are two ways to do this: #1 data.remove(min(data)) data.remove(max(data)) print(sum(data)) Or just #2 print(sum(sorted(data)[1:-1])) # I hope that this helps. Happy coding!
26th Aug 2021, 7:17 AM
Calvin Thomas
Calvin Thomas - avatar
+ 2
Delicate Cat In first one remove that braces inside data list,in print statement And 2nd code is wrong
26th Aug 2021, 7:32 AM
Atul [Inactive]
+ 2
Your first code worked Delicate Cat
26th Aug 2021, 8:07 AM
Atul [Inactive]
+ 2
Atul [Inactive] then your code presented in the question should work. The idea with sort and smaller range in for loop is very good.
26th Aug 2021, 10:45 AM
JaScript
JaScript - avatar
+ 1
Atul [Inactive] What's the question?
26th Aug 2021, 7:10 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
You’re analyzing a data set and need to remove the outliers (the smallest and largest values. The data is stored in a list). Complete the code to remove the smallest and largest elements from the list and output the sum of the remaining numbers. Remember the functions a list supports: min and max can be used to get the smallest and largest numbers.
26th Aug 2021, 7:15 AM
Atul [Inactive]
+ 1
It doesn't pass the test cases. You can run it 😅
26th Aug 2021, 7:41 AM
Atul [Inactive]
+ 1
Delicate Cat Didn't worked
26th Aug 2021, 7:46 AM
Atul [Inactive]
+ 1
Yes you are correct Delicate Cat . Might be the edge cases
26th Aug 2021, 7:49 AM
Atul [Inactive]
+ 1
Atul [Inactive] Would you mind posting the expected output? I guess that the test case is hidden. Should the code take any inputs?
26th Aug 2021, 7:51 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Atul [Inactive] maybe you missed sthg in the question. Delicate Cat has done 3 ways and they have to have worked ..
26th Aug 2021, 7:54 AM
Sacar
Sacar - avatar
+ 1
Delicate Cat I observed that their is no error in logic but presicion
26th Aug 2021, 8:00 AM
Atul [Inactive]
+ 1
Atul [Inactive] Does Simba 's code work? If it does, mine should work too; is that list() typecast really necessary?
26th Aug 2021, 8:00 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Atul [Inactive] There was a small typo in my code. Now, it works.
26th Aug 2021, 8:10 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Pakhi Sahu It's Python, not Javascript.
26th Aug 2021, 9:54 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
JaScript Simba Provided the code and the problem was of precision. And to be very honest sololearn didn't mentioned that in question
26th Aug 2021, 11:42 AM
Atul [Inactive]