하나고 파이썬 기말 예상문제 SET 02¶
이름: ____________ 점수: _____ / 100 난이도: 조금 어려움
1-16번은 객관식, 17-20번은 단답형입니다. 객관식은 가장 알맞은 보기를 하나 고르세요.
객관식¶
1. 다음 코드의 출력으로 옳은 것은?¶
def f(x):
print(x)
return x + 1
print(f(1) + f(2))
① 1 다음 2 다음 5
② 2 다음 1 다음 5
③ 1 다음 3
④ 5만 출력된다
⑤ TypeError
2. 다음 코드의 실행 결과는?¶
x = 5
def power(y):
x **= y
return x
print(power(2))
① 25
② 5
③ 10
④ UnboundLocalError
⑤ NameError
3. 다음 코드의 출력은?¶
x = 10
def f():
global x
x += 10
return x
print(f())
print(x)
① 10 다음 10
② 20 다음 10
③ 20 다음 20
④ None 다음 20
⑤ UnboundLocalError
4. 다음 코드의 출력은?¶
def make(a, b=2, c=3):
return a + b * c
print(make(1))
print(make(1, 4))
print(make(1, 4, 5))
① 6 다음 12 다음 20
② 7 다음 13 다음 21
③ 7 다음 7 다음 7
④ 1 다음 4 다음 5
⑤ TypeError
5. 다음 코드의 출력 순서로 옳은 것은?¶
def say():
print("A")
print("B")
say()
① A 다음 B
② B 다음 A
③ A만 출력된다
④ B만 출력된다
⑤ 함수 정의 시점에 A가 출력된다
6. 다음 코드의 출력은?¶
from random import randint
print(randint(1, 1))
① 0
② 1
③ 2
④ NameError
⑤ ModuleNotFoundError
7. 다음 코드의 실행 결과는?¶
from random import randint
print(random.randint(1, 1))
① 1
② 0
③ NameError
④ AttributeError
⑤ TypeError
8. 다음 코드의 출력은?¶
A = "0"
B = 0
print(A == B)
print(A is B)
① True 다음 True
② True 다음 False
③ False 다음 True
④ False 다음 False
⑤ TypeError
9. 다음 코드의 출력은?¶
class Person:
def __init__(self, name, age, pet=None):
self.name = name
self.age = age
self.pet = pet
p = Person("Hana", 17)
print(p.pet)
① cat
② 17
③ Hana
④ None
⑤ NameError
10. 다음 코드의 출력은?¶
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}"
p = Person("Hana", 17)
p.age += 1
print(p.get_info())
① Hana:17:None
② Hana:18:None
③ Hana:18:pet
④ name:age:pet
⑤ TypeError
11. 다음 코드의 실행 결과는?¶
class A:
def f():
return 1
a = A()
print(a.f())
① 1
② None
③ TypeError
④ NameError
⑤ AttributeError
12. 2_function_test.py의 happy_dance(robot)에 대한 설명으로 옳은 것은?¶
def happy_dance(robot):
for i in range(120):
robot.turn_left()
hana.set_pause(0.3)
① 항상 hana만 회전한다
② 인자로 받은 robot이 회전하고, pause 설정은 hana에 적용된다
③ robot과 hana가 둘 다 120번씩 회전한다
④ robot은 문자열이어야 한다
⑤ return값은 120이다
13. 다음 코드의 실행 결과는?¶
scores = {"Kor": 80, "Eng": 90}
print(scores["Math"])
① 0
② None
③ KeyError
④ NameError
⑤ TypeError
14. 다음 코드의 출력으로 옳은 것은?¶
scores = {"Kor": 80, "Eng": 90, "Math": 70}
for x in scores.keys():
print(x)
① 80, 90, 70이 출력된다
② Kor, Eng, Math가 출력된다
③ key와 value가 한 줄에 같이 출력된다
④ 평균이 출력된다
⑤ TypeError
15. 다음 코드의 출력은?¶
sentiment = {
"negative": ["sad", "blue", "small", "exam", "bad"],
"positive": ["happy", "great", "glad", "better", "saturday"]
}
print(sentiment["positive"][1])
① happy
② great
③ positive
④ blue
⑤ KeyError
16. 5_random_walk.py의 반복문에서 로봇이 시작하자마자 비퍼 위에 있다면 가장 먼저 일어나는 일은?¶
while True:
if hana.on_beeper():
break
direction = # 랜덤 방향 선택
① 랜덤 방향을 먼저 고른다
② 앞이 비었는지 먼저 검사한다
③ 즉시 break로 반복문을 빠져나간다
④ 비퍼를 내려놓는다
⑤ turn_left()를 세 번 실행한다
단답형¶
17. 빈칸에 들어갈 코드를 쓰시오.¶
def turn_right():
hana.turn_left()
hana.turn_left()
hana.____()
18. 빈칸에 들어갈 값을 순서대로 쓰시오.¶
# add1.wld
start = (____, ____, "E")
target_beeper = (____, ____)
19. 빈칸에 들어갈 말을 쓰시오.¶
def BMI(h, w): # h, w는 함수 정의의 ____
return w / h**2
BMI(170, 80) # 170, 80은 함수 호출의 ____
20. 빈칸에 들어갈 숫자를 순서대로 쓰시오.¶
def fahrenheit_to_celsius(F):
return (F - ____) * 5 / ____