Computer Science
Write a program to create a dictionary with the roll number, name and marks of n students in a class, and display the names of students who have secured marks above 75.
Python
Python Dictionaries
14 Likes
Answer
n = int(input("Enter the number of students: "))
student_data = {}
for i in range(n):
roll_number = int(input("Enter roll number for student: "))
name = input("Enter name for student: ")
marks = int(input("Enter marks for student: "))
student_data[roll_number] = {'name': name, 'marks': marks}
print(student_data)
print("Students who have secured marks above 75:")
for roll_number, details in student_data.items():
if details['marks'] > 75:
print(details['name'])
Output
Enter the number of students: 4
Enter roll number for student: 5
Enter name for student: Ashish Kumar
Enter marks for student: 67
Enter roll number for student: 4
Enter name for student: Samay
Enter marks for student: 79
Enter roll number for student: 5
Enter name for student: Rohini
Enter marks for student: 89
Enter roll number for student: 6
Enter name for student: Anusha
Enter marks for student: 73
{5: {'name': 'Rohini', 'marks': 89}, 4: {'name': 'Samay', 'marks': 79}, 6: {'name': 'Anusha', 'marks': 73}}
Students who have secured marks above 75:
Rohini
Samay
Answered By
3 Likes
Related Questions
Draw the structure of the components of a computer and briefly explain the following.
(a) Input Unit
(b) Output Unit
(c) Central Processing Unit
(d) Primary Memory
(e) Secondary Memory
Write a menu-driven program to implement a simple calculator for two numbers given by the user.
Write a program that inputs a list, replicates it twice and then prints the sorted list in ascending and descending orders.
Explain any five social media etiquettes.