콘텐츠로 이동

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

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

1-16번은 객관식, 17-20번은 코드 빈칸 채우기 단답형입니다. 수업 자료 예제를 변형한 문항입니다.


객관식

1. 다음 코드의 출력은?

def outer(x):
    return x + 1

def inner(x):
    return x * x

print(outer(inner(3)))

9
10
16
18
None

2. 다음 코드의 출력은?

def no_return(x):
    x = x * 2

value = no_return(4)
print(value)

4
8
None
0
NameError

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

total_count = 0

def add_one():
    total_count += 1
    return total_count

print(add_one())

0
1
None
UnboundLocalError
NameError

4. 다음 코드의 출력은?

total_count = 0

def add_one():
    global total_count
    total_count += 1
    return total_count

print(add_one())
print(total_count)

1 다음 1
1 다음 0
0 다음 1
None 다음 1
UnboundLocalError

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

from math import sqrt
print(sqrt(9) + sqrt(16))

7
7.0
25
25.0
NameError

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

import math
print(sqrt(16))

4
4.0
math.sqrt
NameError
AttributeError

7. 다음 코드의 출력은?

A = "0"
B = 0
print(type(A).__name__, type(B).__name__)

str int
int str
str str
int int
bool bool

8. 수업 자료의 자동차 예제를 바탕으로 한 코드이다. 출력은?

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

myCar = Car(4, 4, "gasoline")
print(myCar.fuel)

4
seat
gasoline
None
AttributeError

9. 다음 코드의 출력은?

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

myCar = Car(4, 4, "gasoline")
print(myCar.color)

gasoline
4
None
AttributeError
NameError

10. 다음 코드의 출력은?

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)
print(Rectangle.area(r1))

15
8
None
TypeError
AttributeError

11. 다음 코드의 출력은?

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

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

8
15
53
None
TypeError

12. 다음 코드의 출력은?

scores = {"Kor": 80, "Eng": 90, "Math": 70}
print(list(scores.keys())[1])

Kor
Eng
Math
90
KeyError

13. 다음 코드의 출력은?

scores = {"Kor": 80, "Eng": 90, "Math": 70}
print(list(scores.items())[0])

Kor
80
('Kor', 80)
['Kor', 80]
TypeError

14. 다음 코드의 출력은?

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

2
4
5
10
KeyError

15. 다음 중 3_maze.py의 상태로 옳은 것은?

① 완성된 오른손 법칙 알고리즘이 들어 있다
maze1.wld를 불러오고 Robot()을 만든 템플릿이다
add1.wld에서 랜덤 워크를 실행한다
fairy_tale.wld에서 보물을 찾는다
⑤ 비퍼 36개를 수확한다

16. 5_random_walk.py에서 랜덤 방향 선택을 위해 import한 표준 라이브러리는?

math
random
cowsay
pandas
cs1robots_images


단답형

17. 빈칸에 들어갈 키워드를 쓰시오.

def f():
    ____ x
    x += 1

18. 빈칸에 들어갈 클래스 이름을 쓰시오.

print(type("hello"))
# <class '____'>

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

scores = {"Kor": 80, "Eng": 90}
print(list(scores.____())[0])  # ('Kor', 80)

20. 빈칸에 들어갈 파일 이름을 쓰시오.

load_world("____")
hana = Robot()
# 3_maze.py에서 사용하는 세계 파일