<aside> <img src="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" alt="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" width="40px" />

딕셔너리에서 값 가져오기

<aside>

딕셔너리 값 꺼내기

student = {"name": "Alice", "age": 20}
student["name"]

</aside>

<aside>

여러 명의 학생 정보 중에서 특정 학생을 찾기

students = [
    {"name": "Alice", "age": 20},
    {"name": "Bob", "age": 22},
    {"name": "Charlie", "age": 21},
    {"name": "Diana", "age": 19},
    {"name": "Eve", "age": 23}
]

target_name = "Charlie"

for student in students:
    if student["name"] == target_name:
        print("찾은 학생:", student)

<aside>

💬 추가 문제 - 나이가 20세 이상인 학생의 이름과 나이 출력하기

# 리스트 형태로 출력하기

students = [
    {"name": "Alice", "age": 20},
    {"name": "Bob", "age": 22},
    {"name": "Charlie", "age": 21},
    {"name": "Diana", "age": 19},
    {"name": "Eve", "age": 23}
]

students_list = []

for x in students:
  if x['age'] >= 20:
     students_list.append(x['name'])
     students_list.append(x['age'])

print(students_list)
# 딕셔너리 형태로 출력하기

students = [
    {"name": "Alice", "age": 20},
    {"name": "Bob", "age": 22},
    {"name": "Charlie", "age": 21},
    {"name": "Diana", "age": 19},
    {"name": "Eve", "age": 23}
]

students_list = []

for x in students:
  if x['age'] >= 20:
     students_list.append({'name':x['name'],'age':x['age']})

print(students_list)

</aside>

</aside>

<aside> <img src="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" alt="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" width="40px" />

반복문 사용하기

<aside>

조건문 확장하기 - 점수 출력하기

score = 85
score_grade = None

if score >= 90:
    score_grade = "A"
elif score >= 80:
    score_grade = "B"
elif score >= 70:
    score_grade = "C"
elif score >= 60:
    score_grade = "D"
else:
    score_grade = "F"
    
print(f'점수가 {score}이면 등급은 {score_grade}입니다.')

</aside>

<aside>

💬 추가 문제 - split 메소드 사용하기

score = input('점수를 한꺼번에 입력하시오.(점수 입력 시 콤마(,) 사용)')

score_list = score.split(',')
score_grade = None

for x in score_list:
    score = int(x.strip())
    grade = None
    if score >= 90: 
       grade = 'A'
    elif score >= 80:
       grade = 'B'
    elif score >= 70:
       grade = 'C'
    elif score >= 80:
       grade = 'D'
    else:
       grade = 'E'

    print(f'{score}점은 {grade}등급입니다.')

</aside>

</aside>

<aside> <img src="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" alt="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" width="40px" />

반복문 사용하기

<aside>

반복문을 사용해 리스트에서 값 꺼내오기

colors = ["red", "green", "blue"]

for color in colors:
    print(color)

<aside>

💬 추가 문제 - 출력 결과를 다르게 하기

colors = ["red", "green", "blue"]
colors_list = ''

for color in colors:
    colors_list += color + ' '

print(f'선택 가능한 색은 {colors_list}입니다.')
colors = ["red", "green", "blue"]
colors_list = []

for color in colors:
    colors_list.append(color)

print(f'선택 가능한 색은{colors_list}입니다.')

</aside>

</aside>

<aside> <img src="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" alt="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" width="40px" />

리스트의 평균/합계/차이 구하기

<aside>

반복문 또는 내장함수를 사용해 평균 구하기

numbers = [10, 20, 30, 40, 50]
total = 0

for num in numbers:
    total += num 
    
avg_numbers = round(total / len(numbers))

print(avg_numbers)
numbers = [10, 20, 30, 40, 50]
total = sum(numbers)
    
avg_numbers = round(total / len(numbers))

print(avg_numbers)

<aside>

기준 이상 값만 골라 합계 구하기

110 이상의 전환수만 골라 합계 구하기

conversions = [100, 150, 120, 130, 110, 180, 140]
min_value = 110
conversion_beyond = []

for x in conversions:
   if x >= min_value:
      conversion_beyond.append(x)

conversion_beyond_sum = sum(conversion_beyond)

print(conversion_beyond_sum)

</aside>

<aside>

</aside>

<aside>

</aside>

</aside>

<aside> <img src="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" alt="notion://custom_emoji/b602c9b4-c478-4904-8b80-95c0ecff1e9f/2020aba3-9a4b-801f-a730-007ab259a990" width="40px" />

</aside>