콘텐츠로 이동

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

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

1-16번은 객관식, 17-20번은 코드 빈칸 채우기 단답형입니다.


객관식

1. 다음 코드의 출력은?

def f(x):
    return 2 * x

n = 3
n = f(n + 1) + f(n + 2)
print(n)

6
8
10
18
20

2. 다음 코드의 출력은?

def mark(x):
    print(x)
    return x

def add(a, b):
    return a + b

print(add(mark(1), mark(2)))

1 다음 2 다음 3
2 다음 1 다음 3
3 다음 1 다음 2
1 다음 3
TypeError

3. 다음 코드의 출력은?

def avg1(x, y):
    a = (x + y) / 2

def avg2(x, y):
    return (x + y) / 2

print(avg1(2, 4))
print(avg2(2, 4))

3.0 다음 3.0
None 다음 3.0
3.0 다음 None
None 다음 None
NameError

4. 다음 코드의 출력은?

x = 10

def f():
    global x
    x += 10

f()
print(x)

10
20
None
UnboundLocalError
NameError

5. 다음 코드의 출력은?

print(len("Hello"))

4
5
6
Hello
TypeError

6. 함수/라이브러리 분류에 대한 설명으로 옳은 것은?

print()는 외부 라이브러리라서 pip install이 필요하다
math는 사용자 정의 함수이다
cowsay 같은 PyPI 패키지는 보통 설치 후 import한다
def로 만든 함수는 반드시 import해야 쓸 수 있다
⑤ 표준 라이브러리는 파이썬에 포함되어 있지 않다

7. 다음 코드의 출력은?

print(type("0"))

<class 'int'>
<class 'float'>
<class 'str'>
<class 'list'>
<class 'dict'>

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

class Car:
    def __init__(self, wheel):
        self.wheel = wheel

myCar = Car(4)
print(mycar.wheel)

4
None
NameError
AttributeError
TypeError

9. 다음 코드의 출력은?

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)
car1.display_info()

Tayo Bus 2026
2026 Tayo Bus
Bus Tayo 2026
None
TypeError

10. 다음 코드의 출력은?

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

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

2
5
8
15
None

11. 다음 코드의 출력은?

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

KorEng
8090
170
80
KeyError

12. 다음 코드의 출력은?

scores = {"Kor": 80, "Eng": 90, "Math": 70}
v_list = [x for x in scores.values()]
print(v_list)

['Kor', 'Eng', 'Math']
[80, 90, 70]
[('Kor', 80), ('Eng', 90), ('Math', 70)]
dict_values([80, 90, 70])
TypeError

13. 다음 코드의 출력은?

d = {"A": 1, "B": 2, "A": 5}
print(d)

{'A': 1, 'B': 2}
{'A': 5, 'B': 2}
{'A': 1, 'B': 2, 'A': 5}
{'B': 2}
SyntaxError

14. 다음 코드의 출력은?

scores = {"Kor": 80, "Eng": 90, "Math": 70, "Science": 100}
print(len(list(scores.items())))

2
3
4
8
TypeError

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

① 10x10 세계이고 비퍼는 (7, 2)에 있다
② 14x8 세계이고 보물 비퍼는 (5, 6)에 있다
③ 12x12 세계이고 비퍼 36개가 있다
④ 10x10 세계이고 비퍼는 (6, 4)에 있다
⑤ 벽이 전혀 없다

16. front_is_clear(), left_is_clear(), right_is_clear(), on_beeper()의 반환값 자료형으로 가장 알맞은 것은?

int
str
list
bool
dict


단답형

17. 빈칸에 들어갈 변수명을 쓰시오.

def greet(x):
    print("hello", x)
    return x * 2

n = greet("Wolf")
print(____)

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

scores = {"Kor": 80, "Eng": 90}
print(scores[____])     # 80 출력

19. 오른손 법칙 우선순위가 되도록 빈칸을 순서대로 채우시오.

if hana.____():
    turn_right()
    hana.move()
elif hana.____():
    hana.move()
elif hana.____():
    hana.turn_left()
    hana.move()
else:
    turn_around()
    hana.move()

20. 빈칸에 들어갈 숫자를 쓰시오.

count = 0
for i in range(4):
    for j in range(9):
        count += 1
print(count)  # ____