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:

  1. Search for a student’s marks in all subjects.

  2. Sort all lists by student name (A–Z).

  3. Sort in reverse by Maths marks (highest → lowest).

  4. Traverse and print student with all three subject marks.

  5. Reverse traverse the lists.

  6. Find & update a student’s marks in any subject.

  7. Delete a student and their marks from all subjects.

  8. Add a new student with marks in all subjects.

  9. Calculate total marks for each student.

  10. Calculate average marks for each student.

  11. 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

Popular posts from this blog

Python_While_Loop

Python_Lists_Loops

clinical_app