Complete the code to remove the smallest and largest elements from the list and output the sum of the remaining numbers. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Complete the code to remove the smallest and largest elements from the list and output the sum of the remaining numbers.

https://code.sololearn.com/cziSGrWVItWu/?ref=app

18th Apr 2021, 8:16 AM
Akash Prasad
Akash Prasad - avatar
7 Answers
+ 5
Akash Prasad You were very close to your solution. See here https://code.sololearn.com/c7Q3cEs0k6n5/?ref=app
18th Apr 2021, 9:03 AM
A͢J
A͢J - avatar
+ 5
The way you sum here is not a good way, print(data[0]+data[1]+data[2]+data[3]+data[4]+data[5]+data[6]+data[7]+data[8]+data[9]+data[10]+data[11]+data[12]+data[13]+data[14]+data[15]+data[16]+data[17]+data[18]+data[19]+data[20]) Just do it: print(sum(data)) https://code.sololearn.com/cA19a10a23A8/#py Edit:Well, I am thinking what will happen if the max number has two times in a list?Should the code should delete the two number or only one? If you have to delete all those two numbers then you can do this following : https://code.sololearn.com/c0A37A07a173
18th Apr 2021, 8:21 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
You are missing data[21] There were 24 elements in original list 0-23, you removed 2 that leaves 22 in the list 0-21. You could also just use sum(data) instead of adding each individual element like that.
18th Apr 2021, 8:23 AM
ChaoticDawg
ChaoticDawg - avatar
0
What's wrong
18th Apr 2021, 8:16 AM
Akash Prasad
Akash Prasad - avatar
0
I want to input in single line for all elements addition
18th Apr 2021, 8:17 AM
Akash Prasad
Akash Prasad - avatar
0
Akash Prasad Thanks for msging me bro. here is your solution https://code.sololearn.com/cA14a4A23a24/?ref=app
18th Apr 2021, 8:37 AM
CHANDAN ROY
CHANDAN ROY - avatar
0
here's my solution: 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 data.remove(max(data)) data.remove(min(data)) print(sum(data))
8th Sep 2021, 3:50 PM
andrei
andrei - avatar