38.2 Right decision. Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

38.2 Right decision. Python

The proposed solution excludes 1 maximum and 1 minimum, although there are 2 maximum "1024" in the array. Therefore, the proposed solution is wrong Decision 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] a = data.count(max(data)) b = data.count(min(data)) total = 0 for x in data: total += x total = total - (max(data) * a + min(data) * b) print(totals)

29th Mar 2022, 11:32 AM
Ilya Samartsev
Ilya Samartsev - avatar
6 Answers
29th Mar 2022, 11:37 AM
Simba
Simba - avatar
+ 3
Task. Print the sum of all the array values except for all minimum and maximum values. The array that is given in the task has 1 minimum value (0.4) and 2 maximum values (1024) The proposed solution removes 1 maximum and 1 minimum, but the second maximum remains
29th Mar 2022, 11:51 AM
Ilya Samartsev
Ilya Samartsev - avatar
+ 3
Илья Самарцев So 0.4 is the min and 1024 is the max and it says remove "all" max and min values. Therefore, the one 0.4 and the two 1024 values should be removed.
29th Mar 2022, 12:02 PM
Paul K Sadler
Paul K Sadler - avatar
+ 1
Can you post full question? I guess, it asking to subtract max, min values from list sum, then print?
29th Mar 2022, 11:46 AM
Jayakrishna 🇮🇳
0
Yes. It's wrong solution for *all May expecting this kind of excersize i guess print(sum(data) - max(data) - min(data))
29th Mar 2022, 12:39 PM
Jayakrishna 🇮🇳
0
Make the list as a set using set(list_name) , then u will get only unique numbers then u can use ur code
30th Mar 2022, 10:31 AM
RAJESH N
RAJESH N - avatar