하나고 파이썬 기말 예상문제 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.py의 escape()에서 (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
}