+ 1

Program to input name and percentage of 10 students in 10 nested list and print name and %age of the topper

I am stuck, I can't think what to do next. I used split () to make the list nested but can't think of anything to access the person w/ the highest percentage and print it out. https://code.sololearn.com/cDRvV5mVLqA3/?ref=app

3rd Nov 2019, 11:10 AM
Azmat
13 odpowiedzi
3rd Nov 2019, 1:29 PM
Russ
Russ - avatar
+ 5
here is an other version, allowing multiple input without predefining : inp = [] while True: # loop allows multiple input without pre definition tmp = [int(i) if i.isdigit() else i for i in input('input name number (or x for exit): ').split()] if len(tmp) == 1: break inp.append(tmp) print('\nHighest core:',*sorted(inp, key = lambda x: x[1], reverse=True)[0])
3rd Nov 2019, 4:04 PM
Lothar
Lothar - avatar
+ 2
Amzat code modified.
3rd Nov 2019, 1:48 PM
Russ
Russ - avatar
+ 2
high_score = max([k[1] for k in my_list]) Amzat Sure. [k[1] for k in my_list] is a list comprehension that populates a list of the scores (as the score is in element 1) of all elements in my_list. max() then returns the largest of the numbers in that list.
3rd Nov 2019, 6:34 PM
Russ
Russ - avatar
+ 1
name, percentage = input("enter name and marks \n").split() print(f'name={name}, percentage={percentage}') # enter name and marks # name=name1, percentage=percentage1 my_list.append( dict(name=name, percentage=percentage) ) print(my_list) # [{'name': 'name1', 'percentage': 'percentage1'}]
3rd Nov 2019, 12:45 PM
o.gak
o.gak - avatar
+ 1
Lothar thanks although I don't really know much about lambda since I'm an amateur, it does what it's told. Still thanks for your help.
3rd Nov 2019, 4:23 PM
Azmat
+ 1
Russ I understood, Thanks!
3rd Nov 2019, 6:39 PM
Azmat
0
Russ no, the code prints out eveyone's name and modifying the percentages in a weird manner. I need to get the name and percentage of only the top scorer.
3rd Nov 2019, 1:45 PM
Azmat
0
o.gak the code prints all the inputs and the last input in a dictionary, I need it to print details of the top scorer only.
3rd Nov 2019, 1:47 PM
Azmat
0
Russ thanks, but can you elaborate line 9?
3rd Nov 2019, 4:36 PM
Azmat
0
Buen dia alguien que me ayude con un programa que mueste los nombres de 10 trabajadores y sus ventas porfabor
5th Nov 2019, 1:42 AM
David Meza
0
Hello someone help me make a program of 10 workers and their sales of the day and total sale someone help me please
8th Nov 2019, 5:52 AM
David Meza
0
in Python name percentage and age ko kaise print Karen 5 ki range mein
2nd May 2024, 1:25 PM
Future doctor Komal
Future doctor Komal - avatar