Write a program to take in the roll number, name and percentage of marks for n students of
Class X. Write user defined functions to:
1. accept details of the n students (n is the number of students)
2. search details of a particular student on the basis of roll number and display
result
3. display the result of all the students
4. find the topper amongst them
5. find the subject toppers amongst them
(Hint: use Dictionary, where the key can be roll number and the value is an immutable data
type containing name and percentage)
# Python 3.9.5
def stud_details(r_num, name, p_mark, stud_dict):
stud_dict[r_num] = {}
stud_dict[r_num]['name'] = name
stud_dict[r_num]['p_mark'] = p_mark
return stud_dict
def disp_stud_info(r_num, stud_dict):
print(stud_dict[r_num])
def disp_all_stud_data(stud_dict):
for i in range(1, len(stud_dict)+1):
print('Name: ', stud_dict[i]['name'])
print('Marks: ', stud_dict[i]['p_mark'])
def top_stud(stud_dict):
top = {'p_mark': 0}
for i in range(1, len(stud_dict)+1):
if stud_dict[i]['p_mark'] > top['p_mark']:
top['name'] = stud_dict[i]['name']
top['p_mark'] = stud_dict[i]['p_mark']
return top
def main():
# stud_dict = {}
# r_num = 1
# name = 'John'
# p_mark = 70
# stud_dict = stud_details(r_num, name, p_mark, stud_dict)
stud_dict = {
1: {'name': 'John', 'p_mark': 70},
2: {'name': 'Anna', 'p_mark': 80},
3: {'name': 'Anna', 'p_mark': 60}
}
# disp_stud_info(r_num, stud_dict)
# disp_all_stud_data(stud_dict)
print(top_stud(stud_dict))
if __name__ == '__main__':
main()
Comments
Leave a comment