콘텐츠로 이동

하나고 파이썬 기말 예상문제 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.pymaze1.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.____()