하나고 파이썬 기말 예상문제 SET 06¶
이름: ____________ 점수: _____ / 100 난이도: 조금 어려움
1-16번은 객관식, 17-20번은 코드 빈칸 채우기 단답형입니다. 수업 자료 예제를 변형한 문항입니다.
객관식¶
1. 수업 자료의 f(x) = 2x 예제를 파이썬으로 옮긴 코드이다. 출력은?¶
def f(x):
return x * 2
print(f(f(3)))
① 3
② 6
③ 9
④ 12
⑤ None
2. 다음 코드의 출력은?¶
def convert_to_Celsius(Fahrenheit):
return (Fahrenheit - 32) * 5 / 9
temperature = convert_to_Celsius(80)
print(round(temperature, 1))
① 26.0
② 26.7
③ 48.0
④ 80.0
⑤ None
3. 다음 코드에서 BMI = BMI(170, 80) 실행 후 BMI라는 이름이 가리키는 것은?¶
def BMI(h, w):
return w / h**2
BMI = BMI(170, 80)
① 함수 객체
② 문자열 "BMI"
③ 계산 결과인 실수
④ 매개변수 h
⑤ 모듈 이름
4. 다음 코드의 출력은?¶
def greet(x):
print("hello,", x)
return x * 2
n = greet("Cat")
print(n)
① hello, Cat 다음 CatCat
② CatCat 다음 hello, Cat
③ hello, Cat 다음 None
④ Cat 다음 Cat
⑤ TypeError
5. 다음 코드의 출력은?¶
def ice_cream(topping="mint"):
print("ice cream")
print(topping, "on it")
ice_cream()
① ice cream 다음 mint on it
② mint만 출력된다
③ None만 출력된다
④ ice cream 다음 None on it
⑤ TypeError
6. 다음 설명 중 수업 자료의 함수 실행 규칙과 맞는 것은?¶
① 함수 정의문을 만나면 함수 본문이 즉시 실행된다
② 함수 호출 시 인자값이 매개변수에 대입된다
③ return 뒤의 값은 항상 무시된다
④ 지역 변수는 함수 호출이 끝난 뒤에도 반드시 남아 있다
⑤ 인자는 오른쪽에서 왼쪽으로 평가된다
7. 다음 코드의 실행 결과는?¶
def calculate(a, b):
result = a + b
return result
print(result)
① 0
② 7
③ None
④ NameError
⑤ UnboundLocalError
8. 수업 자료의 객체 설명과 가장 맞는 것은?¶
① 객체는 오직 값만 있고 타입은 없다
② 객체는 데이터와 동작을 함께 가질 수 있다
③ id, type, value는 모두 같은 뜻이다
④ 문자열은 객체가 아니다
⑤ 리스트는 클래스에서 만들어진 객체가 아니다
9. 다음 코드의 출력은?¶
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} is {self.age} years old. pet: {self.pet}"
p = Person("Hana", 17)
print(p.get_info())
① Hana is 17 years old. pet: None
② Hana is 17 years old. pet: pet
③ None
④ Hana is age years old. pet: None
⑤ TypeError
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)
r1.height = 4
print(r1.area())
① 15
② 20
③ 9
④ None
⑤ TypeError
11. 다음 코드의 출력은?¶
class Calculator:
def add(self, a, b):
return a + b
def multiply(self, a, b):
return a * b
calc = Calculator()
print(calc.multiply(calc.add(1, 2), 4))
① 7
② 8
③ 12
④ 24
⑤ TypeError
12. 다음 코드의 출력은?¶
dictA = {"Kor": 80, "Eng": 90, "Math": 70, "Science": 100}
print(dictA["Kor"] + dictA["Eng"] + dictA["Math"])
① 240
② 250
③ KorEngMath
④ 80 90 70
⑤ KeyError
13. 다음 코드의 출력은?¶
b_type_dict = {"A": 3, "AB": 3, "B": 4, "O": 5}
print(sum(b_type_dict.values()))
① 4
② 5
③ 12
④ 15
⑤ TypeError
14. 다음 코드의 출력은?¶
favorite_animal = {"cat": 2, "python": 2, "dog": 3}
print(max(favorite_animal.values()))
① cat
② python
③ dog
④ 3
⑤ 7
15. 2_function_test.py의 첫 번째 큰 반복문에서 move_and_drop()은 총 몇 번 호출되는가?¶
for i in range(4):
for j in range(9):
move_and_drop()
① 4번
② 9번
③ 13번
④ 36번
⑤ 40번
16. maze1.wld의 시작 로봇 정보로 옳은 것은?¶
① (1, 1, 'E', 0)
② (6, 4, 'E', 0)
③ (10, 10, 'N', 0)
④ (9, 1, 'E', 0)
⑤ (1, 1, 'N', 36)
단답형¶
17. 빈칸에 들어갈 식을 쓰시오.¶
def convert_to_Celsius(Fahrenheit):
return (Fahrenheit - 32) * ____ / ____
18. 빈칸에 들어갈 속성 이름을 순서대로 쓰시오.¶
class Person:
def __init__(self, name, age, pet=None):
self.____ = name
self.____ = age
self.____ = pet
19. 빈칸에 들어갈 메서드 이름을 쓰시오.¶
b_type_dict = {"A": 3, "AB": 3, "B": 4, "O": 5}
for count in b_type_dict.____():
print(count)
20. 빈칸에 들어갈 숫자를 쓰시오.¶
count = 0
for i in range(4):
for j in range(9):
count += 1
print(count) # ____