I have a question if i have a 12 list of number how do i sum only 5 highest number | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I have a question if i have a 12 list of number how do i sum only 5 highest number

Phython

18th May 2022, 5:49 PM
Aisy Danish Mohd Nazry
Aisy Danish Mohd Nazry - avatar
5 Answers
18th May 2022, 5:55 PM
Aisy Danish Mohd Nazry
Aisy Danish Mohd Nazry - avatar
+ 1
You don't need y input. Remove it. You have now sorted list. Know about list slicing.. and reverse sort, apply sum as sum(list) hope you can do it easily..
18th May 2022, 6:00 PM
Jayakrishna 🇮🇳
0
Do you have some code where you have tried?
18th May 2022, 5:50 PM
Justice
Justice - avatar
0
apply sort on list so list get sorted then use list slicing to extract 5 numbers and apply sum function
18th May 2022, 5:52 PM
Jayakrishna 🇮🇳
0
I did my best but still dont get it
18th May 2022, 5:56 PM
Aisy Danish Mohd Nazry
Aisy Danish Mohd Nazry - avatar