16. create a dictionary with roll number, name, and marks of students in a class, and then display the names of students who have scored marks above 75.
def get_student_details(n):
"""
Creates a dictionary with roll number, name, and marks of n students.
Args:
n: The number of students.
Returns:
A dictionary where keys are roll numbers and values are tuples of (name, marks).
"""
student_details = {}
for i in range(n):
roll_no = int(input("Enter roll number for student {}: ".format(i+1)))
name = input("Enter name for student {}: ".format(i+1))
marks = float(input("Enter marks for student {}: ".format(i+1)))
student_details[roll_no] = (name, marks)
return student_details
def display_toppers(student_details):
"""
Displays the names of students who have scored marks above 75.
Args:
student_details: A dictionary containing student details.
"""
print("\nStudents who scored above 75:")
for roll_no, (name, marks) in student_details.items():
if marks > 75:
print(name)
if __name__ == "__main__":
n = int(input("Enter the number of students: "))
student_data = get_student_details(n)
display_toppers(student_data)
No comments:
Post a Comment