1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] MOOC - Students database (Errors when submitting)

Discussão em 'Python' iniciado por Stack, Setembro 12, 2024.

  1. Stack

    Stack Membro Participativo

    My code is working now. I tested it with the examples MOOC gives and all is good, but I got errors when I try to submit. Any ideas?

    I don't know what to do. I think its something wrong with the code after the if name section.

    My code:

    def add_student(database: dict, name: str):
    if name in database:
    print("This student exists already")

    database[name] = {}

    def add_course(database: dict, name: str, course: tuple):
    if course[1] == 0:
    return
    if course[0] not in database[name]:
    students[name][course[0]] = course[1]
    return
    if course[1] > database[name][course[0]]:
    database[name][course[0]] = course[1]
    return

    def print_student(database: dict, name: str):
    if name not in database:
    print(f"{name}: no such person in the database")
    else:
    if len(database[name]) == 0:
    print(f"{name}:")
    print(" no completed courses")
    else:
    completed_courses = len(database[name])
    sum_grades = 0
    print(f"{name}:")
    print(f" {completed_courses} completed courses:")
    for courses, grades in database[name].items():
    sum_grades += grades
    avg_grade = sum_grades / len(database[name])
    print(f" {courses} {grades}")
    print(f" average grade {avg_grade}")

    def summary(database: dict):
    students = len(database)
    courses_completed = 0
    best_avg = 0
    most_courses = ""
    for student in database:
    total_grade = 0
    for course, grade in database[student].items():
    total_grade += grade
    avg_grade = total_grade / len(database[student])
    if avg_grade > best_avg:
    best_avg = avg_grade
    if len(database[student]) > courses_completed:
    courses_completed = len(database[student])
    most_courses = student
    print(f"students {students}")
    print(f"most courses completed {courses_completed} {most_courses}")
    print(f"best average grade {student} {best_avg}")



    if __name__ == "__main__":
    students = {}
    add_student()
    add_course()
    print_student()
    summary()


    I got a lot of errors when I submit. Examples:

    [​IMG]

    I'm expecting no errors because the code is working.

    Continue reading...

Compartilhe esta Página