Q; Write a function to display the result of examination of students. Following requirements must be
fulfilled:
i. Read the names and marks of at least 5 students, data should be acquired from the user
and saved as dictionary (using a function named get info)
ii. Rank the top three students with highest marks (make a function named top3)
iii. Give cash rewards. Rs. 5000 for first rank, Rs. 3000 for second rank, Rs. 1000 for
third rank. Value cannot be modified (function name should be cashprize)
def getinfo():
student ={}
for row in range(5):
name = input("Enter the student name\t")
mark =int(input("Enter the student mark\t"))
student[name] = mark
sorted_students = sorted(student.items(), key=lambda x: x[1], reverse=True)
return sorted_students
def top3():
students = getinfo()
#stu = students.items()
return students[:3]
def cashprize():
top = top3()
print(str(top[0]) +"\tRs.5000")
print(str(top[1]) +"\tRs.3000")
print(str(top[2]) + "\tRs. 1000")
cashprize()
Comments
Leave a comment