Given the names and grades for each student in a class of N students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.
Note: If there are multiple students with the second lowest grade, order their names alphabetically and print each name on a new line.Go to problem statement.
Explanation Video:
Youtube Channel partner: CodingCart
Mentor: Satyendra Jaiswal
Langauge: Python
Source Code: Nested Lists solution
n=int(input())
res=[]
grade=[]
for i in range(n):
name=input()
mark=float(input())
res.append([name,mark])
grade.append(mark) #calculation 2nd lowest
#print(res)
#print(grade)
grade=sorted(set(grade)) #sorted unique
#print(grade)
m=grade[1]
#print(m)
name=[]
for val in res:
if m==val[1]:
name.append(val[0])
#print(name) #unsorted
name.sort()
#print(name) #sorted
for nm in name:
print(nm)
If you need homework assignment help then here are some of our services-
Like this article? Follow us on Facebook and LinkedIn. You can also subscribe to our Youtube Channel.
This post is in partnership with CodingCart.