하나고 파이썬 기말 예상문제 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에서 사용하는 세계 파일