Menu
Coddy logo textTech

En Başarılı Öğrenciler

Coddy'nin Python Journey'sinin Logic & Flow bölümünün bir parçası — ders 45 / 78.

challenge icon

Görev

Kolay

Bir argüman alan filter_top_students adında bir fonksiyon oluşturun: threshold (float). Fonksiyon şunları yapmalıdır:

  1. student_records sözlüğü üzerinde gezinin ve ortalama notu belirtilen threshold değerinden büyük olan tüm öğrencileri bulun.
  2. Her öğrencinin ortalama notunu almak için calculate_average_grade fonksiyonunu kullanın.
  3. Başarılı öğrencilerin isimlerinden oluşan bir liste döndürün.
  4. Kriterleri karşılayan öğrenci yoksa boş bir liste döndürün.

Kodunuzun en altına aşağıdaki kod bloğunu ekleyin (veya mevcut olanla değiştirin):

add_student("Alice", 20, ["Math", "Physics"])
add_student("Bob", 22, ["Math", "Biology"])
add_student("Diana", 23, ["Chemistry", "Physics"])
add_grade("Alice", 90)
add_grade("Alice", 85)
add_grade("Bob", 75)
add_grade("Diana", 95)
print(filter_top_students(80))  # ["Alice", "Diana"] döndürmeli
print(filter_top_students(90))  # ["Diana"] döndürmeli
print(filter_top_students(100))  # Boş bir liste döndürmeli

Tam işlevsel bir program oluşturmak için sözlükleri, kümeleri ve karar verme yapılarını nasıl birleştirdiğiniz üzerine bir an düşünün. Harika iş! 🚀

Kendin dene

student_records = {}

def add_student(name, age, courses):
    if name in student_records:
        print(f"Student '{name}' already exists.")
        return
    student_records[name] = {"age": age, "grades": set(), "courses": set(courses)}
    print(f"Student '{name}' added successfully.")

def add_grade(name, grade):
    if name not in student_records:
        print(f"Student '{name}' not found.")
        return
    student_records[name]["grades"].add(grade)
    print(f"Grade {grade} added for student '{name}'.")

def is_enrolled(name, course):
    if name not in student_records:
        print(f"Student '{name}' not found.")
        return False
    return course in student_records[name]["courses"]

def calculate_average_grade(name):
    if name not in student_records:
        print(f"Student '{name}' not found.")
        return None
    grades = student_records[name]["grades"]
    if not grades:
        return 0
    return sum(grades) / len(grades)

def list_students_by_course(course):
    students_in_course = []
    for name, details in student_records.items():
        if course in details["courses"]:
            students_in_course.append(name)
    return students_in_course


add_student("Alice", 20, ["Math", "Physics"])
add_student("Bob", 22, ["Math", "Biology"])
add_student("Diana", 23, ["Chemistry", "Physics"])
print(list_students_by_course("Math"))  # Should return ["Alice", "Bob"]
print(list_students_by_course("Physics"))  # Should return ["Alice", "Diana"]
print(list_students_by_course("Biology"))  # Should return ["Bob"]
print(list_students_by_course("History"))  # Should return an empty list

Logic & Flow bölümündeki tüm dersler