Python_Multiple_Parallel_list_operations
Multiple Lists (students, maths, physics, english)
You are given four parallel lists:
-
students = ["Alice", "Bob", "Charlie", "David", "Eve"] -
maths = [85, 92, 78, 90, 88] -
physics = [80, 95, 70, 85, 89] -
english = [82, 88, 75, 92, 84]
Write a Python program to:
-
Search for a student’s marks in all subjects.
-
Sort all lists by student name (A–Z).
-
Sort in reverse by Maths marks (highest → lowest).
-
Traverse and print student with all three subject marks.
-
Reverse traverse the lists.
-
Find & update a student’s marks in any subject.
-
Delete a student and their marks from all subjects.
-
Add a new student with marks in all subjects.
-
Calculate total marks for each student.
-
Calculate average marks for each student.
-
Display a Rank List (students sorted by total marks in descending order).
# Parallel lists
students = ["Alice", "Bob", "Charlie", "David", "Eve"]
maths = [85, 92, 78, 90, 88]
physics = [80, 95, 70, 85, 89]
english = [82, 88, 75, 92, 84]
# --- Rank List (sort by total marks, highest first) ---
n = len(students)
for i in range(n-1):
for j in range(i+1, n):
total_i = maths[i] + physics[i] + english[i]
total_j = maths[j] + physics[j] + english[j]
if total_i < total_j: # swap for descending order
students[i], students[j] = students[j], students[i]
maths[i], maths[j] = maths[j], maths[i]
physics[i], physics[j] = physics[j], physics[i]
english[i], english[j] = english[j], english[i]
# --- Print Rank List ---
print("Rank List (by Total Marks):")
for i in range(len(students)):
total = maths[i] + physics[i] + english[i]
avg = total / 3
print(f"Rank {i+1}: {students[i]} -> Total:{total}, Average:{avg:.2f}")
Comments
Post a Comment