콘텐츠로 이동

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

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

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


객관식

1. 다음 긴 코드의 출력으로 옳은 것은?

def convert_to_Celsius(F):
    return (F - 32) * 5 / 9

def label_temperature(F):
    C = convert_to_Celsius(F)
    if C >= 30:
        return "hot"
    elif C >= 20:
        return "warm"
    else:
        return "cool"

temps = [68, 80, 95]
result = []
for t in temps:
    result.append(label_temperature(t))

print(result)

['cool', 'warm', 'hot']
['warm', 'warm', 'hot']
['cool', 'hot', 'hot']
[20.0, 26.6, 35.0]
TypeError

2. 다음 코드의 출력은?

def f(x):
    return x + 2

def g(x):
    return f(x) * f(x + 1)

print(g(3))

15
25
30
36
None

3. 다음 코드의 출력은?

x = 1

def a():
    x = 2
    return x

def b():
    return x + 3

print(a())
print(b())

2 다음 4
2 다음 5
1 다음 4
1 다음 5
UnboundLocalError

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

def add_stamp(stamp=0):
    stamp += 1
    return stamp

stamp = 7
print(add_stamp())
print(stamp)

1 다음 7
8 다음 8
1 다음 1
8 다음 7
UnboundLocalError

5. 다음 코드의 출력은?

import math
from random import randint

print(math.sqrt(25))
print(randint(2, 2))

5 다음 2
5.0 다음 2
25 다음 2
5.0 다음 NameError
ModuleNotFoundError

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

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}"

people = [
    Person("Hana", 17, "cat"),
    Person("Min", 16),
]

people[1].pet = "dog"
people[0].age += 1

for p in people:
    print(p.get_info())

Hana:17:cat 다음 Min:16:None
Hana:18:cat 다음 Min:16:dog
Hana:18:dog 다음 Min:16:dog
Hana:17:cat 다음 Min:16:dog
TypeError

7. 다음 코드의 출력은?

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}"

car1 = Car("Tayo", "Bus", 2026)
print(car1.display_info().split()[1])

2026
Tayo
Bus
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 = [Rectangle(2, 3), Rectangle(4, 5)]
total = 0
for r in rectangles:
    total += r.area()
print(total)

14
20
26
40
TypeError

9. 다음 코드의 출력은?

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

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

calc = Calculator()
numbers = [calc.add(1, 2), calc.multiply(2, 3)]
print(max(numbers))

2
3
6
9
TypeError

10. 다음 코드의 출력은?

scores = {"Kor": 80, "Eng": 90, "Math": 70, "Science": 100}
passed = []
for subject, score in scores.items():
    if score >= 85:
        passed.append(subject)
print(passed)

['Kor', 'Eng']
['Eng', 'Science']
[90, 100]
['Kor', 'Eng', 'Math', 'Science']
TypeError

11. 다음 코드의 출력은?

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

count = 0
for word in sentiment["positive"]:
    if len(word) >= 5:
        count += 1
print(count)

2
3
4
5
TypeError

12. 다음 코드의 출력은?

b_type_list = ["A", "AB", "B", "O", "AB", "O", "B", "O", "O", "O", "B", "A", "B", "AB", "A"]
count_B = 0
for x in b_type_list:
    if x == "B":
        count_B += 1
print(count_B)

3
4
5
15
TypeError

13. 다음 코드의 출력은?

scores = {"Kor": 80, "Eng": 90, "Math": 70}
result = {k: ("Pass" if v >= 80 else "Fail") for k, v in scores.items()}
print(result["Math"])

Pass
Fail
70
Math
KeyError

14. 다음 중 4_friend.py의 수업 목표와 가장 가까운 것은?

① 함수 기본값만 연습한다
② 두 로봇이 보물 비퍼를 찾는 객체/메서드 실습이다
③ 딕셔너리 평균만 계산한다
④ 단위 변환만 수행한다
harvest2.wld의 비퍼 36개를 모두 줍는다

15. harvest2.wld에 대한 설명으로 옳은 것은?

① 10x10 세계이며 비퍼 1개가 있다
② 14x8 세계이며 보물은 (5, 6)이다
③ 12x12 세계이며 비퍼 36개가 배치되어 있다
④ 10x10 세계이며 로봇은 (9, 1)에서 시작한다
⑤ 벽 24개가 있는 미로이다

16. 다음 코드에서 hana가 비퍼 위에 있지 않고 앞이 막혀 있다면 어떤 문제가 발생할 가능성이 가장 큰가?

while True:
    if hana.on_beeper():
        break
    direction = random.choice([turn_right, hana.turn_left, turn_around])
    direction()
    hana.move()

① 정상적으로 항상 이동한다
hana.move()에서 벽 때문에 오류가 날 수 있다
random.choice는 리스트를 받을 수 없다
direction()은 항상 문자열이다
⑤ 반복문이 한 번도 실행되지 않는다


단답형

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

def label_temperature(F):
    C = (F - 32) * 5 / 9
    return C

print(round(label_temperature(95), 1))  # ____

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

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

r = Rectangle()
r.width = 6
r.height = 7
print(r.____())  # 42

19. 빈칸에 들어갈 조건식을 쓰시오.

scores = {"Kor": 80, "Eng": 90, "Math": 70}
result = ["Pass" if ____ else "Fail" for x in scores.values()]

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

if hana.____():
    break
# 5_random_walk.py에서 목표 비퍼를 밟았는지 검사