콘텐츠로 이동

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

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

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


객관식

1. 다음 코드의 출력은?

def f(x):
    if x > 0:
        return x
    print("after")

print(f(1))

after 다음 1
1
None
after 다음 None
TypeError

2. 다음 코드의 출력은?

y = 10

def f(x):
    return x * y

print(f(2))

2
10
20
NameError
UnboundLocalError

3. 다음 코드의 출력은?

x = 5
y = 10

def f(x):
    x = 2
    return x * y

print(f(x))
print(x)

20 다음 5
50 다음 5
20 다음 2
50 다음 2
UnboundLocalError

4. 다음 코드의 출력은?

def ice_cream(topping="mint", stamp=0):
    return topping, stamp + 1

print(ice_cream())
print(ice_cream("cherry", 7))

('mint', 1) 다음 ('cherry', 8)
('mint', 0) 다음 ('cherry', 7)
('cherry', 8) 다음 ('mint', 1)
None 다음 None
TypeError

5. 다음 코드의 출력은?

import random as r
print(r.randint(1, 1))

0
1
random
NameError
ModuleNotFoundError

6. 다음 코드의 출력은?

import math
print(math.sqrt(16))

4
4.0
16
NameError
AttributeError

7. 다음 코드의 출력은?

a = [1]
b = a
c = [1]
print(a == c, a is b, a is c)

True True True
True True False
True False False
False True False
False False False

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

class Rectangle:
    def __init__(self, width, height):
        self.width = width
        self.height = height

r = Rectangle(5)

① 정상 실행된다
width가 5, heightNone이 된다
TypeError
NameError
AttributeError

9. 다음 코드의 출력은?

class Rectangle:
    def __init__(self, width, height):
        self.width = width
        self.height = height

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

r1 = Rectangle(5, 3)
r2 = Rectangle(2, 4)
r1.width = 10
print(r1.area(), r2.area())

15 8
30 8
30 30
10 8
TypeError

10. 다음 코드의 출력은?

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

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

calc = Calculator()
print(calc.add(5, 3))
print(calc.multiply(4, 7))

8 다음 28
15 다음 11
None 다음 None
5 3 다음 4 7
TypeError

11. 다음 코드의 출력은?

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

80.0
85.0
90.0
340
TypeError

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

scores = {"Kor": 80, "Eng": 90}
total = 0
for i in scores.keys():
    total += i
print(total)

170
KorEng
0
TypeError
KeyError

13. 다음 코드의 출력은?

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

sad
blue
exam
bad
negative

14. add34.wld에 들어 있는 비퍼 총개수는?

beepers = {
    (10, 1): 1,
    (10, 10): 2,
    (1, 10): 3
}

① 3개
② 4개
③ 5개
④ 6개
⑤ 10개

15. 2_function_test.py가 정상적으로 한 바퀴 내려놓고 한 바퀴 줍는다고 할 때 최종 비퍼 가방 개수는?

hana = Robot(beepers=100)
# 36개 drop 후 같은 36개 pick

① 36개
② 64개
③ 72개
④ 100개
⑤ 136개

16. 오른손 법칙 코드에서 오른쪽과 앞이 모두 비어 있을 때 선택되는 분기는?

elif hana.front_is_clear()
elif hana.left_is_clear()
else
if hana.right_is_clear()
⑤ 조건을 모두 실행한다


단답형

17. 빈칸에 들어갈 메서드 이름을 순서대로 쓰시오.

# cs1robots 기본 동작 함수
hana.____()          # 한 칸 앞으로 이동
hana.____()          # 왼쪽으로 90도 회전
hana.____()          # 비퍼 줍기
hana.____()          # 비퍼 내려놓기

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

def f(x):
    x = 2 * x

result = f(3)
print(result is ____)

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

scores = {"Kor": 80, "Eng": 90}
for key, value in scores.____():
    print(key, value)

20. 빈칸에 들어갈 지역 변수 이름을 모두 쓰시오.

def calculate(a, b):
    result = a + b
    return result

# calculate 함수 호출 프레임의 지역 변수: ____, ____, ____