Why does this code not match the expected values? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why does this code not match the expected values?

After trying several times still I am not able to get the pass for the test case. Why is this? Question Text List Functions 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. You can do it! 94% of our learners solved this START SOLVING

20th Nov 2021, 4:10 PM
Sanjay Kamath
Sanjay Kamath - avatar
20 Answers
+ 1
No. Sanjay I mean list data? Yes.. from search bar I checked that you missed value 78 in list at end.. edit: Sanjay Kamath https://www.sololearn.com/Discuss/2892148/?ref=app
21st Nov 2021, 5:24 PM
Jayakrishna 🇮🇳
+ 5
=> to get this task done, we can use the following 3 steps or lines of code: ▪︎ remove the minimum value from the list like this: data.remove(max(data)) ▪︎ remove the maximum value from the list like this: data.remove(min(data)) ▪︎build the total sum of the list by using sum() function and print the result: print(sum(data))
20th Nov 2021, 7:24 PM
Lothar
Lothar - avatar
+ 3
You remove all values that match max and min. But there are 2 items which match max - 1024 - so you end up removing 3 items, instead of 2. Make your code remove only one item each for max and min. Warning 2 below can put you in the way. Some important things to notice: 1. You initialize variables x, y and i with values that will never be used. So initializing is just not needeed. 2. You create a new list only to remove 2 items. Lists are mutable. So you can, instead, just remove from the first list. The second one is just not needeed. 3. Linking your code works best in the question itself. Doing it in an answer only makes it harder for those wanting to help.
21st Nov 2021, 3:45 AM
Emerson Prado
Emerson Prado - avatar
+ 2
It worked😃. Thanks all. 👍
22nd Nov 2021, 1:40 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Post the code
20th Nov 2021, 4:17 PM
Atul [Inactive]
+ 1
And the question too
20th Nov 2021, 4:17 PM
Atul [Inactive]
+ 1
https://code.sololearn.com/c8N82JoSF98s/?ref=app Compiles but values don't match.🙄
20th Nov 2021, 4:19 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Are you trying to sum of list without min,max values? round ( int(...) ) , Here round is no effect. round(number,0) also same as round(number) You can find max, min then remove from list then just apply sum(list) will work for what you trying there.. What actually trying with round() there ? To floor down value or To round up value? edit: Sanjay Kamath after removing redundant code, this is same as you trying ... it just finding min,max then forming new list without min,max and finding sum of all integer converted data values.. hope it helps... 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] #your code goes here x = min(data) y = max(data) #print(x, y) newlist=[] i=0 for i in data: if x!=i and y!=i: newlist.append(int(i)) #print(newlist) sum=0 for k in newlist: sum+=k print(sum)
20th Nov 2021, 4:48 PM
Jayakrishna 🇮🇳
+ 1
You have to find where is going wrong, by observing the output. What is your expected output and what your output? If you need only remove first single min and Max values then use just #data = [ ] #add data values here. 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] #your code goes here Sanjay Kamath data.remove(min(data)) data.remove(max(data)) print(sum(data)) These are enough steps to work done. Pls Don't change original question, you can add as edit or in new post , that will give clarity and not confuses. Hope it helps..
21st Nov 2021, 11:12 AM
Jayakrishna 🇮🇳
+ 1
The original question lists only 1 test-case, which is hidden, and hence I am unable to point out why this is so. 38.2
21st Nov 2021, 11:41 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Are you tried the last one I posted? and tell How , if not work?
21st Nov 2021, 12:00 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 Yes. I simply cannot figure out why it is failing. Can we make a hidden test-case visible? If so, how?
21st Nov 2021, 12:25 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Sanjay Kamath Are you sure about the list data ? I think you missing or wrong data you have taken? Check again.. *edit: no way to visible
21st Nov 2021, 3:47 PM
Jayakrishna 🇮🇳
+ 1
Yes Python for beginners 38.2
21st Nov 2021, 4:41 PM
Sanjay Kamath
Sanjay Kamath - avatar
21st Nov 2021, 4:49 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Jayakrishna🇮🇳 my sum is 2728.32
21st Nov 2021, 4:56 PM
Sanjay Kamath
Sanjay Kamath - avatar
0
Atul [Inactive] The question updated.
21st Nov 2021, 2:05 AM
Sanjay Kamath
Sanjay Kamath - avatar
0
Still not working.
21st Nov 2021, 2:18 AM
Sanjay Kamath
Sanjay Kamath - avatar
0
Emerson Prado Python for beginners 38.2....still not working
21st Nov 2021, 8:21 AM
Sanjay Kamath
Sanjay Kamath - avatar
0
Any feedback please... Tried out your solutions..no success...
21st Nov 2021, 10:24 AM
Sanjay Kamath
Sanjay Kamath - avatar