콘텐츠로 이동

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

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

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


객관식

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

def inch_to_cm(x):
    return x * 2.54

def feet_to_cm(x):
    return x * 30.48

def convert(unit, value):
    if unit == "inch":
        return inch_to_cm(value)
    elif unit == "feet":
        return feet_to_cm(value)
    else:
        return None

values = [convert("inch", 10), convert("feet", 2), convert("mile", 1)]
print(values)

[25.4, 60.96, None]
[2.54, 30.48, 1]
[25.4, 60.96, 0]
[None, None, None]
TypeError

2. 다음 코드의 출력은?

def get_average(scores):
    return sum(scores) / len(scores)

student1 = [80, 90, 70]
student2 = [95, 85, 100]
print(get_average(student1) < get_average(student2))

True
False
80.0
93.33333333333333
TypeError

3. 다음 코드의 출력은?

def step(x):
    print("step", x)
    return x + 1

a = step(1)
b = step(a)
print(b)

step 1 다음 step 2 다음 3
step 1 다음 2
step 2 다음 step 1 다음 3
3만 출력된다
None

4. 다음 코드의 출력은?

x = 10

def f():
    y = x + 5
    return y

print(f())

5
10
15
NameError
UnboundLocalError

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

x = 10

def f():
    x = x + 5
    return x

print(f())

15
10
5
UnboundLocalError
NameError

6. 다음 코드의 출력은?

class Person:
    def __init__(self, name, age, pet=None):
        self.name = name
        self.age = age
        self.pet = pet

    def birthday(self):
        self.age += 1

    def get_info(self):
        return f"{self.name}:{self.age}:{self.pet}"

p = Person("Hana", 17, "cat")
p.birthday()
p.birthday()
print(p.get_info())

Hana:17:cat
Hana:18:cat
Hana:19:cat
Hana:19:None
TypeError

7. 다음 코드의 출력은?

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)
info = car1.display_info()
print(info == None)

2026 Tayo Bus 다음 True
2026 Tayo Bus 다음 False
True만 출력된다
None만 출력된다
TypeError

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

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

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

rectangles = {
    "small": Rectangle(2, 3),
    "large": Rectangle(5, 6),
}

for name in rectangles.keys():
    if rectangles[name].area() >= 10:
        print(name)

small만 출력된다
large만 출력된다
small 다음 large
④ 아무것도 출력되지 않는다
TypeError

9. 다음 코드의 출력은?

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

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

calc = Calculator()
print(calc.add(calc.multiply(2, 5), 3))

10
13
16
25
TypeError

10. 다음 코드의 출력은?

scores = {"Kor": 80, "Eng": 90, "Math": 70, "Science": 100}
total = 0
count = 0
for subject, score in scores.items():
    if subject != "Math":
        total += score
        count += 1
print(total / count)

85.0
90.0
270
3
TypeError

11. 다음 코드의 출력은?

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

word = "exam"
result = "positive"
for key, words in sentiment.items():
    if word in words:
        result = key
print(result)

positive
negative
exam
words
KeyError

12. 다음 코드의 출력은?

b_type_dict = {"A": 3, "AB": 3, "B": 4, "O": 5}
result = []
for blood, count in b_type_dict.items():
    if count >= 4:
        result.append(blood)
print(result)

['A', 'AB']
['B', 'O']
[4, 5]
['A', 'AB', 'B', 'O']
TypeError

13. 다음 코드의 출력은?

scores = {"Kor": 80, "Eng": 90}
scores["Math"] = 70
scores["Kor"] += 5
print(scores)

{'Kor': 80, 'Eng': 90}
{'Kor': 85, 'Eng': 90, 'Math': 70}
{'Kor': 80, 'Eng': 90, 'Math': 70}
{'Kor': 85, 'Math': 70}
TypeError

14. 1_myrobot.pyescape()에서 (6, 4) 위치 검사와 on_beeper() 검사의 순서로 옳은 것은?

on_beeper()를 먼저 검사하고 그 다음 위치를 검사한다
② 위치를 먼저 검사하고, 통과하면 on_beeper()를 검사한다
③ 두 조건을 동시에 검사한다
④ 위치 검사는 반복문 밖에 있다
⑤ 비퍼 검사는 없다

15. turn_around()이 동쪽을 바라보는 로봇에게 실행되면 최종 방향은?

def turn_around():
    hana.turn_left()
    hana.turn_left()

① 동쪽
② 서쪽
③ 남쪽
④ 북쪽
⑤ 방향이 사라진다

16. fairy_tale.wld의 보물 비퍼 좌표는?

(6, 4)
(7, 2)
(5, 6)
(10, 10)
(1, 1)


단답형

17. 빈칸에 들어갈 값을 쓰시오.

def get_average(scores):
    return sum(scores) / len(scores)

print(get_average([80, 90, 70]))  # ____

18. 빈칸에 들어갈 메서드 이름을 쓰시오.

class Person:
    def birthday(self):
        self.age += 1

p.birthday()
p.____()
# 나이가 총 2 증가하도록 만들기

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

sentiment = {"negative": ["sad", "exam"], "positive": ["happy"]}
print(sentiment[____][1])  # exam

20. 빈칸에 들어갈 좌표를 쓰시오.

# fairy_tale.wld
beepers = {
    ____: 1
}