콘텐츠로 이동

파이썬 객관식 심화 — SET 01

이름: ____________ 점수: _____ / 100 난이도: ★★★☆☆

각 코드의 실행 결과 또는 옳은 설명을 보기에서 하나 고르세요. (문항당 10점, 범위: 1~8장 종합)


1. (자료형) 다음 코드의 출력은?

a = "5"
b = 2
print(a * b + a)

1255557552TypeError

2. (연산자) 다음 코드의 출력은?

print(2 + 3 * 4 ** 2)

5019610076144

3. (while) 다음 코드의 출력은?

i = 1
result = 0
while i < 6:
    result += i
    i += 2
print(result)

6915416

4. (for) 다음 코드의 출력은?

total = 0
for i in range(10, 0, -3):
    total += i
print(total)

2225193021

5. (함수) 다음 코드의 출력은?

def f(x):
    if x > 0:
        return x * 2
print(f(3), f(-1))

6 -16 None6 0None NoneError

6. (클래스) 다음 코드의 출력은?

class Box:
    items = []
    def add(self, x):
        self.items.append(x)

a = Box()
b = Box()
a.add(1)
b.add(2)
print(a.items)

[1][1, 2][2][]Error

7. (예외 처리) 다음 코드의 출력은?

try:
    nums = [1, 2, 3]
    print(nums[5])
except IndexError:
    print("A")
except ValueError:
    print("B")
finally:
    print("C")

AA 다음 줄에 CB 다음 줄에 CCA B C

8. (모듈) 다음 코드의 출력은?

import math
print(math.floor(3.9) + math.ceil(3.1))

6786.07.0

9. (리스트) 다음 코드의 출력은?

nums = [0, 1, 2, 3, 4, 5]
print(nums[::-2])

[0, 2, 4][5, 3, 1][4, 2, 0][5, 4, 3, 2, 1, 0][1, 3, 5]

10. (딕셔너리) 다음 코드의 출력은?

d = {"a": 1, "b": 2}
print(d.get("c", 0) + d.get("a"))

013KeyErrorNone