하나고 파이썬 기말 예상문제 SET 01¶
이름: ____________ 점수: _____ / 100 난이도: 조금 어려움
1-16번은 객관식, 17-20번은 단답형입니다. 객관식은 가장 알맞은 보기를 하나 고르세요.
객관식¶
1. 다음 코드의 출력으로 옳은 것은?¶
def f(x):
print("f", x)
return x + 1
def g(x):
print("g", x)
return x * 2
print(f(g(3)))
① g 3 다음 f 6 다음 7
② f 3 다음 g 4 다음 8
③ g 3 다음 f 3 다음 4
④ f 6 다음 g 3 다음 7
⑤ 7만 출력된다
2. 다음 코드의 출력으로 옳은 것은?¶
x = 4
def foo(x):
x = x + 3
return x
print(foo(x))
print(x)
① 7 다음 7
② 7 다음 4
③ 4 다음 7
④ 4 다음 4
⑤ NameError
3. 다음 코드의 실행 결과는?¶
n = 10
def update():
print(n)
n = 3
update()
① 10이 출력된 뒤 n이 3이 된다
② 3이 출력된다
③ UnboundLocalError가 발생한다
④ NameError가 발생한다
⑤ 아무것도 출력되지 않고 정상 종료된다
4. 다음 코드의 출력은?¶
def average(x, y):
a = (x + y) / 2
print(average(2, 4))
① 3
② 3.0
③ a
④ None
⑤ TypeError
5. 다음 코드의 출력으로 옳은 것은?¶
def ice_cream(topping="mint", stamp=0):
return stamp + 1
print(ice_cream("cherry", 7))
print(ice_cream("cherry"))
print(ice_cream())
① 7 다음 0 다음 0
② 8 다음 8 다음 1
③ 1 다음 1 다음 1
④ 8 다음 1 다음 0
⑤ 8 다음 1 다음 1
6. 다음 코드의 실행 결과는?¶
from math import sqrt
print(math.sqrt(16))
① 4
② 4.0
③ NameError
④ ModuleNotFoundError
⑤ AttributeError
7. 다음 설명 중 옳은 것은?¶
① 내장 함수는 항상 import가 필요하다
② 표준 라이브러리는 반드시 pip install을 먼저 해야 한다
③ 외부 라이브러리는 설치 없이 항상 바로 import된다
④ 사용자 정의 함수는 def로 만들 수 있다
⑤ from module import func는 모듈 이름도 현재 파일에 자동 등록한다
8. 다음 코드의 출력은?¶
scores = {"Kor": 90, "Eng": 80, "Kor": 70}
print(scores["Kor"])
① 90
② 70
③ [90, 70]
④ KeyError
⑤ SyntaxError
9. 다음 코드의 출력은?¶
scores = {"Kor": 80, "Eng": 90, "Math": 70, "Science": 100}
total = 0
for x in scores.values():
total += x
print(total / 4)
① 80
② 85
③ 85.0
④ 340
⑤ TypeError
10. 다음 코드의 출력은?¶
scores = {"A": 90, "B": 65, "C": 70}
result = ["Pass" if x >= 70 else "Fail" for x in scores.values()]
print(result)
① ['Pass', 'Fail', 'Pass']
② ['Pass', 'Pass', 'Fail']
③ ['A', 'B', 'C']
④ [90, 65, 70]
⑤ TypeError
11. 다음 코드의 출력은?¶
class Person:
def __init__(self, name, age, pet=None):
self.name = name
self.age = age
self.pet = pet
def get_info(self):
return f"{self.name} is {self.age} years old. pet: {self.pet}"
p1 = Person("Hana", 17, "cat")
print(p1.get_info())
① Hana is 17 years old.
② Hana is 17 years old. pet: cat
③ Hana is age years old. pet: pet
④ None
⑤ TypeError
12. 다음 코드의 출력으로 옳은 것은?¶
class Car:
def __init__(self, brand, model, year):
self.brand = brand
self.model = model
self.year = year
def display_info(self):
print(f"{self.year} {self.brand} {self.model}")
car1 = Car("Tayo", "Bus", 2026)
r = car1.display_info()
print(r)
① 2026 Tayo Bus만 출력된다
② None만 출력된다
③ Tayo Bus 2026 다음 None
④ 2026 Tayo Bus 다음 None
⑤ TypeError
13. 다음 코드의 출력은?¶
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)
print(r1.area())
① 15
② 8
③ None
④ 5 3
⑤ TypeError
14. 동쪽을 바라보는 로봇에게 아래 함수가 실행되면 최종 방향은?¶
def turn_right():
hana.turn_left()
hana.turn_left()
hana.turn_left()
① 동쪽
② 북쪽
③ 남쪽
④ 서쪽
⑤ 방향이 바뀌지 않는다
15. escape()의 조건 분기에서 오른쪽과 앞이 모두 비어 있다면 실행되는 동작은?¶
if hana.right_is_clear():
turn_right()
hana.move()
elif hana.front_is_clear():
hana.move()
elif hana.left_is_clear():
hana.turn_left()
hana.move()
else:
turn_around()
hana.move()
① 앞쪽으로 이동한다
② 오른쪽으로 회전한 뒤 이동한다
③ 왼쪽으로 회전한 뒤 이동한다
④ 유턴한 뒤 이동한다
⑤ 아무 동작도 하지 않는다
16. 실제 1_myrobot.py와 maze1.wld 기준으로 옳은 설명은?¶
① 출구 조건은 (10, 10)이다
② 시작 위치는 (6, 4)이다
③ 비퍼는 (10, 10)에 있다
④ 로봇은 북쪽을 보고 시작한다
⑤ 비퍼는 (6, 4)에 있고 코드도 그 위치에서 멈춘다
단답형¶
17. 빈칸에 들어갈 코드를 쓰시오.¶
def turn_around():
hana.____()
hana.____()
18. 빈칸에 들어갈 코드를 쓰시오.¶
scores = {"Kor": 80, "Eng": 90, "Math": 70, "Science": 100}
for i in scores.____():
print(i)
19. 빈칸에 들어갈 코드를 쓰시오.¶
class Car:
def display_info(self):
print("2026 Tayo Bus")
car1 = Car()
r = car1.display_info()
print(r is ____)
20. 빈칸에 들어갈 코드를 순서대로 쓰시오.¶
def move_and_drop():
hana.____()
if not hana.on_beeper():
hana.____()