Menu
Coddy logo textTech

Kayıtlı mı?

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

challenge icon

Görev

Kolay

name (string) ve course (string) olmak üzere iki argüman alan is_enrolled adında bir fonksiyon oluşturun. Fonksiyon şunları yapmalıdır:

  1. Öğrenci isminin student_records sözlüğünde mevcut olup olmadığını kontrol edin.
    • Eğer mevcut değilse, "Student '<name>' not found." yazdırın ve False döndürün.
  2. Eğer isim mevcutsa, course değerinin öğrencinin courses kümesinde (set) olup olmadığını kontrol edin.
    • Eğer öyleyse, True döndürün.
    • Değilse, False 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, ["Biology", "Chemistry"])
add_grade("Alice", 90)
add_grade("Alice", 85)
add_grade("Bob", 75)
add_grade("Charlie", 80)  # Non-existent student
print(is_enrolled("Alice", "Math"))  # Should return True
print(is_enrolled("Alice", "Biology"))  # Should return False
print(is_enrolled("Bob", "Biology"))  # Should return True
print(is_enrolled("Charlie", "Math"))  # Non-existent student, should print message and return False

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}'.")


add_student("Alice", 20, ["Math", "Physics"])
add_student("Bob", 22, ["Biology", "Chemistry"])
add_grade("Alice", 90)
add_grade("Alice", 85)
add_grade("Bob", 75)
add_grade("Charlie", 80)  # Non-existent student
print(student_records)

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