+ 2
Complete the code to remove the smallest and largest elements from the list and output the sum of the remaining numbers.
7 Answers
+ 5
Akash Prasad
You were very close to your solution.
See here
https://code.sololearn.com/c7Q3cEs0k6n5/?ref=app
+ 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
+ 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.
0
What's wrong
0
I want to input in single line for all elements addition
0
Akash Prasad
Thanks for msging me bro. here is your solution
https://code.sololearn.com/cA14a4A23a24/?ref=app
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))