콘텐츠로 이동

하나고 파이썬 기말 예상문제 SET 10

이름: ____________ 점수: _____ / 100 난이도: 조금 어려움

1-16번은 객관식, 17-20번은 코드 빈칸 채우기 단답형입니다. 수업 자료 예제를 변형한 문항이며, 긴 코드 실행 추적 문항을 포함합니다.


객관식

1. 다음 긴 코드의 출력은?

def f(x):
    return x * 2

def calculate(a, b):
    result = f(a) + f(b)
    return result

x = 3
y = 4
z = calculate(x, y)
print(z)
print(x, y)

14 다음 3 4
14 다음 6 8
7 다음 3 4
24 다음 3 4
NameError

2. 다음 코드의 출력은?

def ice_cream(topping="mint", stamp=0):
    print(topping)
    return stamp + 1

stamp = ice_cream("cherry", 7)
stamp = ice_cream(stamp=stamp)
print(stamp)

cherry 다음 mint 다음 9
cherry 다음 cherry 다음 9
mint 다음 cherry 다음 9
cherry 다음 mint 다음 8
TypeError

3. 다음 코드의 실행 결과는?

def outer():
    local_value = 10
    return local_value

outer()
print(local_value)

10
None
0
NameError
UnboundLocalError

4. 다음 코드의 출력은?

from math import sqrt

def hypotenuse(a, b):
    return sqrt(a * a + b * b)

print(hypotenuse(3, 4))

5
5.0
7
25
NameError

5. 다음 긴 코드의 출력은?

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}({self.age})-{self.pet}"

class Classroom:
    def __init__(self):
        self.students = []

    def add_student(self, student):
        self.students.append(student)

    def count_pets(self):
        count = 0
        for student in self.students:
            if student.pet != None:
                count += 1
        return count

room = Classroom()
room.add_student(Person("Hana", 17, "cat"))
room.add_student(Person("Min", 16))
room.add_student(Person("Jun", 17, "dog"))
print(room.count_pets())

0
1
2
3
TypeError

6. 다음 코드의 출력은?

class Car:
    def __init__(self, brand, model, year):
        self.brand = brand
        self.model = model
        self.year = year

    def display_info(self):
        return f"{self.year} {self.brand} {self.model}"

cars = [Car("Tayo", "Bus", 2026), Car("Mini", "Car", 2025)]
print(cars[0].display_info())
print(cars[1].year)

2026 Tayo Bus 다음 2025
Tayo Bus 2026 다음 2025
2026 Tayo Bus 다음 Mini
None 다음 2025
TypeError

7. 다음 코드의 출력은?

class Rectangle:
    def __init__(self, width, height):
        self.width = width
        self.height = height

    def area(self):
        return self.width * self.height

r = Rectangle(3, 4)
print(r.area() == 12)

True
False
12
None
TypeError

8. 다음 긴 코드의 출력은?

class Calculator:
    def add(self, a, b):
        return a + b

    def multiply(self, a, b):
        return a * b

calc = Calculator()
scores = {"Kor": 80, "Eng": 90, "Math": 70}
total = 0
for score in scores.values():
    total = calc.add(total, score)
average = total / len(scores)
print(average)

80
80.0
240
3
TypeError

9. 다음 코드의 출력은?

scores = {"Kor": 80, "Eng": 90, "Math": 70}
print([k for k, v in scores.items() if v < 85])

['Kor', 'Math']
['Eng']
[80, 70]
['Kor', 'Eng', 'Math']
TypeError

10. 다음 코드의 출력은?

sentiment = {
    "negative": ["sad", "blue", "small", "exam", "bad"],
    "positive": ["happy", "great", "glad", "better", "saturday"]
}
print(sentiment["positive"][-1])

happy
great
better
saturday
IndexError

11. 다음 코드의 출력은?

b_type_dict = {"A": 3, "AB": 3, "B": 4, "O": 5}
print(b_type_dict["AB"] == b_type_dict["A"])

True
False
3
AB
KeyError

12. 다음 코드의 출력은?

favorite_animal = {"cat": 2, "python": 2, "dog": 3}
for animal in favorite_animal.keys():
    if favorite_animal[animal] == 2:
        print(animal)

cat 다음 python
dog만 출력된다
2 다음 2
cat 다음 dog
TypeError

13. 다음 코드에서 오른쪽이 막혀 있고 앞은 비어 있다면 실행되는 줄은?

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()

turn_right(); hana.move()
hana.move()
hana.turn_left(); hana.move()
turn_around(); hana.move()
⑤ 아무 줄도 실행되지 않는다

14. 다음 move_and_pick() 설명으로 옳은 것은?

def move_and_pick():
    hana.move()
    if hana.on_beeper():
        hana.pick_beeper()

① 현재 칸에서 비퍼를 먼저 줍고 이동한다
② 이동한 뒤 그 칸에 비퍼가 있으면 줍는다
③ 이동하지 않고 비퍼만 줍는다
④ 비퍼가 없으면 내려놓는다
⑤ 항상 오류가 난다

15. add1.wld에서 로봇 시작 정보와 목표 비퍼 위치의 조합으로 옳은 것은?

① 시작 (1, 1, 'E'), 비퍼 (6, 4)
② 시작 (9, 1, 'E'), 비퍼 (7, 2)
③ 시작 (6, 1, 'E'), 비퍼 (10, 10)
④ 시작 (1, 1, 'E'), 비퍼 (5, 6)
⑤ 시작 (1, 1, 'E'), 비퍼 36개

16. 다음 중 수업 자료의 dict 설명과 가장 맞는 것은?

① 딕셔너리는 항상 숫자 인덱스로만 접근한다
② 딕셔너리는 key를 이용해 value에 접근한다
③ 딕셔너리는 value를 저장할 수 없다
④ 딕셔너리는 반복문에서 사용할 수 없다
⑤ 딕셔너리는 리스트와 완전히 같은 자료형이다


단답형

17. 빈칸에 들어갈 키워드를 쓰시오.

def f(x):
    ____ x * 2

18. 빈칸에 들어갈 클래스 이름을 쓰시오.

class ____:
    def add(self, a, b):
        return a + b

19. 빈칸에 들어갈 코드를 쓰시오.

scores = {"Kor": 80, "Eng": 90, "Math": 70}
low = [k for k, v in scores.items() if ____]
print(low)  # ['Kor', 'Math']

20. 빈칸에 들어갈 메서드 이름을 순서대로 쓰시오.

def move_and_pick():
    hana.____()
    if hana.on_beeper():
        hana.____()