[부스트코스] 코칭스터디 9기 : AI Basic 2023 1주차 미션(Q3, Q4, Q5) 변형 문제 풀이

2023. 1. 15. 23:55BOOTCAMP/boostcourse AI BASIC 2023

Q3. 각 학생들의 평균 점수를 출력하시오.

 

Input

score = [(100, 96), (94, 89), (60, 54), (73, 83), (76, 82)]

def get_avg(score):
    for index, point in enumerate(score):
        print(f'{index+1} 번, 평균 : {sum(point)/len(point):.1f}')
get_avg(score)

 

Output

1 번, 평균 : 98.0
2 번, 평균 : 91.5
3 번, 평균 : 57.0
4 번, 평균 : 78.0
5 번, 평균 : 79.0

Q4. 2 개의 딕셔너리 객체를 합쳐 출력하시오.

 

Input

dict_first = {'파인애플': 35, '바나나': 19, '망고': 10, '키위': 14}
dict_second = {'파인애플': 3, '망고': 32, '바나나': 12, '수박': 32}

def merge_dict(dict_first, dict_second):
   result  = dict_first
   temp = list(dict_second.keys())
   for i in range(len(dict_second)):
       if temp[i] in result:
          result[temp[i]] += dict_second[temp[i]]
       else:
          result[temp[i]] = dict_second[temp[i]]
   return result
print(merge_dict(dict_first, dict_second))

 

Output

{'파인애플': 38, '바나나': 31, '망고': 42, '키위': 14, '수박': 32}

Q5.  string 안에서의 숫 자를 제거한 후 string만 남은 리스트를 출력하시오.

 

Input

def find_string(inputs):
    no_digits = []
    result = ''
    for i in inputs:
        if not i.isdigit():
            result = no_digits.append(i)
        else: 
            result = ''.join(no_digits)
    return result
inputs = "cat32dog16cow5"
string_list = find_string(inputs)

print(string_list)

 

Output

 

catdogcow