def divide(dividend, divisor):
    if divisor == 0:
        raise ZeroDivisionError("Divisor cannot be 0")

    return dividend / divisor


# grades = []

# print("Welcome to the average grade program")
# try:
#     average = divide(sum(grades), len(grades))
#     # print(f"The average grade is {average} ")
# except ZeroDivisionError as e:
#     print(e)
#     print("The are no grades yet in your list")
# else:
#     print(f"The average grade is {average} ")
# finally:
#     print("Thank you!")

students = [
    {"name": "Michelangelo", "grades": [50]},
    {"name": "Donatelo", "grades": [86, 95]},
    {"name": "Leonardo", "grades": [79, 91]},
    {"name": "Rafel", "grades": [97, 94]},
]

try:
    for student in students:
        name = student["name"]
        grades = student["grades"]
        average = divide(sum(grades), len(grades))
        print(f"name {name} averaged: {average} ")
except ZeroDivisionError:
    print(f"ERROR: {name} has no grades")
else:
    print("--All students average calculated--")
finally:
    print("End of calculation")
