# Lists Mini Project — Grade Book
# nested lists, averages per subject, overall average
# redhorndev.com

# ─────────────────────────────────────────────
# Setup
# ─────────────────────────────────────────────

subjects = ["Math", "English", "Biology"]
grades = [[], [], []]           # one inner list per subject

# ─────────────────────────────────────────────
# Main loop
# ─────────────────────────────────────────────

while True:
    print("\n1 — Add Math grade")
    print("2 — Add English grade")
    print("3 — Add Biology grade")
    print("4 — Show averages")
    print("5 — Quit")
    choice = input("Your choice: ")

    if choice in ("1", "2", "3"):
        index = int(choice) - 1                         # "1" → 0, "2" → 1, "3" → 2
        grade = float(input(f"{subjects[index]} grade: "))
        grades[index].append(grade)
        print("Added.")

    elif choice == "4":
        print()
        total_sum = 0
        total_count = 0

        for i in range(len(subjects)):
            if len(grades[i]) == 0:
                print(f"{subjects[i]:8} no grades yet.")
            else:
                avg = sum(grades[i]) / len(grades[i])
                print(f"{subjects[i]:8} average {avg:.2f}")
                total_sum += sum(grades[i])
                total_count += len(grades[i])

        if total_count > 0:
            print(f"\nOverall average: {total_sum / total_count:.2f}")

    elif choice == "5":
        print("Done. Out.")
        break

    else:
        print("Invalid choice. Enter 1 to 5.")
