하나고 파이썬 기말 예상문제 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에서 목표 비퍼를 밟았는지 검사