Class 11 Practical Programs
Student Marks Analysis
AIM
To write a Python program to display the names and marks of students who scored more than 75 from a given dictionary.
Key Concepts:
- • Dictionary: Key-value pairs for storing student data
- • Iteration: Looping through dictionary items
- • Conditional Logic: Filtering based on marks criteria
ALGORITHM
- Start
- Create a dictionary with student names as keys and marks as values
- Loop through each student in the dictionary
- Check if the student's marks are greater than 75
- If yes, print the student name and marks
- Repeat for all students
- Stop
PROGRAM
# Dictionary of students and marks
students = {
"Alice": 82,
"Bob": 70,
"Charlie": 90,
"David": 65,
"Eva": 78,
"Frank": 95,
"Grace": 73,
"Henry": 88
}
print("Students with marks above 75:")
print("-" * 30)
# Loop through dictionary
for name, marks in students.items():
if marks > 75:
print(f"{name}: {marks}")
# Additional analysis
print("\n" + "=" * 30)
print("STATISTICAL ANALYSIS")
print("=" * 30)
# Count students above 75
count_above_75 = sum(1 for marks in students.values() if marks > 75)
total_students = len(students)
print(f"Total students: {total_students}")
print(f"Students above 75: {count_above_75}")
print(f"Percentage: {(count_above_75/total_students)*100:.1f}%")
# Find highest and lowest marks
highest_marks = max(students.values())
lowest_marks = min(students.values())
print(f"Highest marks: {highest_marks}")
print(f"Lowest marks: {lowest_marks}")
# Calculate average
average_marks = sum(students.values()) / len(students)
print(f"Average marks: {average_marks:.2f}")OUTPUT
Students with marks above 75:
------------------------------
Alice: 82
Charlie: 90
Eva: 78
Frank: 95
Henry: 88
==============================
STATISTICAL ANALYSIS
==============================
Total students: 8
Students above 75: 5
Percentage: 62.5%
Highest marks: 95
Lowest marks: 65
Average marks: 78.88
CONCLUSION
The program successfully demonstrates dictionary manipulation and conditional filtering. It efficiently identifies students with marks above 75 and provides additional statistical analysis including percentage calculations, highest/lowest marks, and average computation.
VIVA QUESTIONS
What is a dictionary in Python?
A dictionary is a collection of key-value pairs that is unordered, changeable, and indexed. Keys must be unique and immutable.
How do you iterate through a dictionary?
Use dict.items() to get both key and value, dict.keys() for keys only, or dict.values() for values only.
What is the difference between dict.items() and dict.values()?
dict.items() returns key-value pairs as tuples, while dict.values() returns only the values.
How would you find the student with highest marks?
Use max(students, key=students.get) to get the key with maximum value, or max(students.values()) for just the value.
Can dictionary keys be modified?
No, dictionary keys are immutable. You cannot change a key directly; you must delete the old key-value pair and add a new one.
How do you add a new student to the dictionary?
Use students["NewStudent"] = marks or students.update({"NewStudent": marks}).
What happens if you try to access a non-existent key?
Python raises a KeyError. Use dict.get(key, default) to avoid this error.
How would you sort students by marks?
Use sorted(students.items(), key=lambda x: x[1], reverse=True) to sort by marks in descending order.
Related Resources
Similar Programs
Theory Topics
Practice More
💡 Pro Tip
Use dict.get(key, default) to safely access dictionary values without KeyError.
🎯 Key Learning
Dictionary comprehension: {k: v for k, v in dict.items() if condition}