Menu
Coddy logo textTech

학생 추가

Coddy Python 여정의 Logic & Flow 섹션에 포함된 레슨 — 78개 중 40번째.

challenge icon

챌린지

쉬움

name (문자열), age (정수), 그리고 courses (문자열 리스트)라는 세 개의 인자를 받는 add_student라는 이름의 함수를 생성하세요. 이 함수는 다음을 수행해야 합니다:

  1. student_records 딕셔너리에 해당 학생 이름이 이미 존재하는지 확인합니다. 만약 존재한다면, "Student '<name>' already exists."를 출력합니다.
  2. 이름이 존재하지 않는다면, age, grades를 위한 빈 세트(이 모델은 각 성적 값이 고유하다고 가정합니다), 그리고 courses 세트와 함께 student_records에 추가합니다.
  3. "Student '<name>' added successfully."를 출력합니다.

코드의 맨 아래에 다음 코드 블록을 추가하세요:

add_student("Alice", 20, ["Math", "Physics"])
add_student("Bob", 22, ["Biology", "Chemistry"])
print(student_records)

직접 해보기

student_records = {}

Logic & Flow의 모든 레슨