하나고 파이썬 기말 예상문제 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.____()