파이썬 객관식 심화 — SET 03¶
이름: ____________ 점수: _____ / 100 난이도: ★★★★☆
각 코드의 실행 결과 또는 옳은 설명을 보기에서 하나 고르세요. (문항당 10점, 범위: 1~8장 종합)
1. (자료형) 다음 코드의 출력은?¶
print(int("10") + float("2.5"))
① 12 ② 12.5 ③ 1010 ④ Error ⑤ 102.5
2. (연산자) 다음 코드의 출력은?¶
print(True or False and False)
① True ② False ③ Error ④ None ⑤ 1
3. (while) 다음 코드의 출력은?¶
i = 0
while True:
i += 1
if i * i >= 20:
break
print(i)
① 4 ② 5 ③ 20 ④ 25 ⑤ 무한 루프
4. (for) 다음 코드의 출력은?¶
s = "abcde"
result = ""
for i in range(len(s)):
if i % 2 == 0:
result += s[i]
print(result)
① abcde ② ace ③ bd ④ acee ⑤ eca
5. (함수) 다음 코드의 출력은?¶
def divmod2(a, b):
return a // b, a % b
q, r = divmod2(17, 5)
print(q * 10 + r)
① 32 ② 17 ③ 5 ④ 23 ⑤ 35
6. (클래스) 다음 코드의 출력은?¶
class Acc:
def __init__(self):
self.bal = 0
def add(self, x):
self.bal += x
a = Acc()
b = Acc()
a.add(100)
a.add(50)
b.add(20)
print(a.bal, b.bal)
① 150 20 ② 170 170 ③ 150 150 ④ 100 20 ⑤ 170 20
7. (예외 처리) 다음 코드의 출력은?¶
try:
x = 10 / 2
except ZeroDivisionError:
print("A")
else:
print("B")
finally:
print("C")
① A C ② B C ③ A B C ④ C ⑤ B
8. (모듈) 다음 코드의 출력은?¶
import math
print(math.sqrt(16) + math.pi // 3)
① 5.0 ② 5 ③ 4.0 ④ 7.04 ⑤ 5.14
9. (리스트) 다음 코드의 출력은?¶
nums = [3, 1, 2]
x = nums.sort()
print(x)
① [1, 2, 3] ② None ③ [3, 1, 2] ④ Error ⑤ [3, 2, 1]
10. (딕셔너리) 다음 코드의 출력은?¶
d = {"a": 1, "b": 2, "c": 3}
total = 0
for k, v in d.items():
if v % 2 == 1:
total += v
print(total)
① 6 ② 4 ③ 2 ④ 3 ⑤ 1