Professional Documents
Culture Documents
수업 시간에 사용한 Google Colaboratory 파이썬 3.7 버전 기준으로 작성된 코드입니다. 알맞은
보기를 고르시오.
a = 10
b = 3
c = a ** b
d = a // b
e = a % b
1. 실행 후 c의 값은?
1) 10 2) 30 3) 90 4) 100 5) 1000
2. 실행 후 d의 값은?
1) 1.1111111 2) 3 3) 3.3333333 4) 10 5) 30
3. 실행 후 e의 값은?
1) 1 2) 2 3) 3 4) 3.3333333 5) 7
if = 10
then = 20
else = if + then
print(else)
[실행결과]
SyntaxError: Invalid syntax
4. 오류가 발생한 원인은?
3) 들여쓰기(indentation)가 잘못되었다.
5) 줄 끝에 세미콜론을 쓰지 않았다.
다음 코드를 보고 질문에 답하시오.
a = 10
a += 10
print(a)
a -= 10
print(a)
5. 첫번째 print문에서 출력되는 값은?
1) 0 2) 10 3) 20 4) 90 5) 100
1) 0 2) 10 3) 20 4) 90 5) 100
a = 10
b = 2
c = 10 / 2
print(type(c))
7. 실행 후 출력되는 값은?
1) <class 'bool'>
2) <class 'complex'>
3) <class 'float'>
4) <class 'int'>
5) <class 'str'>
1) 0 2) 1 3) 2 4) 3 5) 4
9. 실행 후 b의 값은?
10. 실행 후 c의 값은?
sum = 0
for i in range(0,3):
sum += i
print(sum)
11. 위 코드의 출력 결과는?
1) 1 2) 2 3) 3 4) 6 5) 10
sum = 0
i = 0
while sum < 5:
i += 1
sum += i
12. 실행 후 i의 값은?
1) 1 2) 2 3) 3 4) 4 5) 5
1) 1 2) 2 3) 3 4) 6 5) 10
a = 0
while a < 10:
if a > 3:
break
a += 1
14. 실행 후 a의 값은?
1) 1 2) 2 3) 3 4) 4 5) 5
1) 1 2) 5 3) 6 4) 7 5) 9
def increase1():
global a
b = 2
a += 1
b += 1
def increase2(x):
x += 1
return x
a = 1
b = 2
increase1()
c = 3
d = 4
increase2(c)
d = increase2(d)
16. 실행 후 a의 값은?
1) 1 2) 2 3) 3 4) 4 5) 5
17. 실행 후 b의 값은?
1) 1 2) 2 3) 3 4) 4 5) 5
18. 실행 후 c의 값은?
1) 1 2) 2 3) 3 4) 4 5) 5
19. 실행 후 d의 값은?
1) 1 2) 2 3) 3 4) 4 5) 5
20. math 모듈에서 pow() 함수를 import해서 사용하고자 한다. 올바른 방법은?
5) library math.pow()
2) Internet
3) Hypertext
4) HTTP
5) HTML
2) html
3) ul
4) h1
5) span
import re
str = "Looking at a fat cat with a bat"
matches = re.findall("(.at)", str)
print(len(matches))
1) 0 2) 1 3) 3 4) 4 5) 12
24. 텍스트 파일을 열어서 내용을 출력하는 코드이다. 물음표에 들어갈 명령어는?
class Fighter:
def __init__(self, level):
self.level = level
self.power = level * 2
def train(self):
self.power += 2
tom = Fighter(3)
tom.train()
print(tom.power)
1) 3 2) 4 3) 6 4) 8 5) 9
26. ipywidgets를 이용해 다음과 같은 형태로 버튼을 클릭할 때마다 횟수가 1씩 증가하는 코드이
다. 물음표 자리에 들어갈 코드는?
import ipywidgets as w
def gogo(self):
global clicks
clicks += 1
out.clear_output()
with out:
print("클릭수 = {}".format(clicks))
but = w.Button(description="클릭")
out = w.Output()
but.on_click(???)
clicks = 0
with out:
print("클릭수 = 0")
display(but, out)
1) click 2) gogo 3) object 4) input 5) ipywidgets
27. Pillow 모듈을 이용해 사진을 좌우반전해 저장하는 코드이다. 물음표 자리에 들어갈 코드는?
<출력결과>
*
**
***
****
*****
<코드>
<실행내용>
print(abc(4, 3))
print(abc(2, 3))
<출력결과>
16
4
<코드>