하나고 파이썬 기말 예상문제 SET 03¶
이름: ____________ 점수: _____ / 100 난이도: 조금 어려움
1-16번은 객관식, 17-20번은 코드 빈칸 채우기 단답형입니다.
객관식¶
1. 다음 코드의 출력은?¶
def f(x):
if x > 0:
return x
print("after")
print(f(1))
① after 다음 1
② 1
③ None
④ after 다음 None
⑤ TypeError
2. 다음 코드의 출력은?¶
y = 10
def f(x):
return x * y
print(f(2))
① 2
② 10
③ 20
④ NameError
⑤ UnboundLocalError
3. 다음 코드의 출력은?¶
x = 5
y = 10
def f(x):
x = 2
return x * y
print(f(x))
print(x)
① 20 다음 5
② 50 다음 5
③ 20 다음 2
④ 50 다음 2
⑤ UnboundLocalError
4. 다음 코드의 출력은?¶
def ice_cream(topping="mint", stamp=0):
return topping, stamp + 1
print(ice_cream())
print(ice_cream("cherry", 7))
① ('mint', 1) 다음 ('cherry', 8)
② ('mint', 0) 다음 ('cherry', 7)
③ ('cherry', 8) 다음 ('mint', 1)
④ None 다음 None
⑤ TypeError
5. 다음 코드의 출력은?¶
import random as r
print(r.randint(1, 1))
① 0
② 1
③ random
④ NameError
⑤ ModuleNotFoundError
6. 다음 코드의 출력은?¶
import math
print(math.sqrt(16))
① 4
② 4.0
③ 16
④ NameError
⑤ AttributeError
7. 다음 코드의 출력은?¶
a = [1]
b = a
c = [1]
print(a == c, a is b, a is c)
① True True True
② True True False
③ True False False
④ False True False
⑤ False False False
8. 다음 코드의 실행 결과는?¶
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
r = Rectangle(5)
① 정상 실행된다
② width가 5, height가 None이 된다
③ TypeError
④ NameError
⑤ AttributeError
9. 다음 코드의 출력은?¶
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def area(self):
return self.width * self.height
r1 = Rectangle(5, 3)
r2 = Rectangle(2, 4)
r1.width = 10
print(r1.area(), r2.area())
① 15 8
② 30 8
③ 30 30
④ 10 8
⑤ TypeError
10. 다음 코드의 출력은?¶
class Calculator:
def add(self, a, b):
return a + b
def multiply(self, a, b):
return a * b
calc = Calculator()
print(calc.add(5, 3))
print(calc.multiply(4, 7))
① 8 다음 28
② 15 다음 11
③ None 다음 None
④ 5 3 다음 4 7
⑤ TypeError
11. 다음 코드의 출력은?¶
scores = {"Kor": 80, "Eng": 90, "Math": 70, "Science": 100}
print(sum(scores.values()) / len(scores))
① 80.0
② 85.0
③ 90.0
④ 340
⑤ TypeError
12. 다음 코드의 실행 결과는?¶
scores = {"Kor": 80, "Eng": 90}
total = 0
for i in scores.keys():
total += i
print(total)
① 170
② KorEng
③ 0
④ TypeError
⑤ KeyError
13. 다음 코드의 출력은?¶
sentiment = {
"negative": ["sad", "blue", "small", "exam", "bad"],
"positive": ["happy", "great", "glad", "better", "saturday"]
}
print(sentiment["negative"][3])
① sad
② blue
③ exam
④ bad
⑤ negative
14. add34.wld에 들어 있는 비퍼 총개수는?¶
beepers = {
(10, 1): 1,
(10, 10): 2,
(1, 10): 3
}
① 3개
② 4개
③ 5개
④ 6개
⑤ 10개
15. 2_function_test.py가 정상적으로 한 바퀴 내려놓고 한 바퀴 줍는다고 할 때 최종 비퍼 가방 개수는?¶
hana = Robot(beepers=100)
# 36개 drop 후 같은 36개 pick
① 36개
② 64개
③ 72개
④ 100개
⑤ 136개
16. 오른손 법칙 코드에서 오른쪽과 앞이 모두 비어 있을 때 선택되는 분기는?¶
① elif hana.front_is_clear()
② elif hana.left_is_clear()
③ else
④ if hana.right_is_clear()
⑤ 조건을 모두 실행한다
단답형¶
17. 빈칸에 들어갈 메서드 이름을 순서대로 쓰시오.¶
# cs1robots 기본 동작 함수
hana.____() # 한 칸 앞으로 이동
hana.____() # 왼쪽으로 90도 회전
hana.____() # 비퍼 줍기
hana.____() # 비퍼 내려놓기
18. 빈칸에 들어갈 값을 쓰시오.¶
def f(x):
x = 2 * x
result = f(3)
print(result is ____)
19. 빈칸에 들어갈 메서드 이름을 쓰시오.¶
scores = {"Kor": 80, "Eng": 90}
for key, value in scores.____():
print(key, value)
20. 빈칸에 들어갈 지역 변수 이름을 모두 쓰시오.¶
def calculate(a, b):
result = a + b
return result
# calculate 함수 호출 프레임의 지역 변수: ____, ____, ____