+ 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
13 odpowiedzi
+ 2
Something like this?
https://code.sololearn.com/cy5vml5LdiG6/?ref=app
+ 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])
+ 2
Amzat code modified.
+ 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.
+ 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'}]
+ 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.
+ 1
Russ I understood, Thanks!
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.
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.
0
Russ thanks, but can you elaborate line 9?
0
Buen dia alguien que me ayude con un programa que mueste los nombres de 10 trabajadores y sus ventas porfabor
0
Hello someone help me make a program of 10 workers and their sales of the day and total sale someone help me please
0
in Python name percentage and age ko kaise print Karen 5 ki range mein