Python빈칸 채우기어려움 · 30점#함수#변수#람다#클로저#변수 범위

73. 클로저 카운터와 변수 범위 함정

다음 Python 프로그램에서 add는 바깥 함수의 total과 모듈의 count를 함께 바꾼다. 실행 결과가 "6 5 4", "[20, 20, 20] 4" 두 줄이 되도록 빈칸 ①, ②에 들어갈 키워드를 쓰시오.

1count = 0
2
3
4def make_counter(step):
5 total = 0
6
7 def add():
8 ( ① ) total
9 ( ② ) count
10 total += step
11 count += 1
12 return total
13
14 return add
15
16
17def reset():
18 count = 100
19
20
21c1 = make_counter(2)
22c2 = make_counter(5)
23c1()
24c1()
25print(c1(), c2(), count)
26reset()
27fs = [lambda: i * 10 for i in range(3)]
28print([f() for f in fs], count)

해설을 먼저 보면 이후 정답 시 점수가 50%만 반영됩니다.