1. float는?
[답변] 실수형
2. if 1>2 :
print("yes")
else :
print("No")
[답변] yes
3. a = "good morning"
len(a)
[답변] 12
4. a = " good morning "
공백을 제거해주세요
[답변] a.strip()
5. 다음 코드에 따라 a와 b의 값을 입력했을 때
a + b = 1122 가 나오도록 해주세요
[답변]
a = input()
b = input()
a + b
-> input으로 받으면 문자형이기 때문에 +로 이어주면 되는 것
6. 루트를 사용하고 싶다면 math의 어떤 것을 사용해야 하는가
[답변] sqrt
7. 정수 n을 입력하면 n! 이 출력되도록 하는 코드는?
[답변]
import math
n = int(input())
factorial(n)
8. 입력받은 값이 짝수면 "짝" 홀수면 "홀" 이 출력되도록 하는 코드는?
[답변]
n = int(input())
if n%2 == 0:
print("짝")
else :
print("홀")
9. 문자열과 관련된 함수를 4개 이상 적어주세요
[답변] upper(), lower(), str(), strip(), len()
10. 문자열 a에 포함되어있는 알파벳 e의 갯수는?
a = "blueberry smoothie"
[답변] a.count('e')
11. 1 부터 1000 사이의 3등분해 4개의 숫자로 나눠라
[답변]
import numpy as np
np.linspace(1, 1000, 4)
12. input()함수에 입력된 숫자는 정수형이다
[답변] x
13. 0 부터 2파이까지 sin과 cos의 그래프를 함께 그려라
[답변]
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 11)
plt.plot(x**2)
14. 아래 문자열을 보기처럼 변환하시오
' LIFE-IS-SHORT,-WE-NEED-PYTHON '
[보기] Life is short, we need python
[답변]
a.title().strip().replace('-',' ')
-> 이렇게 하면 단어 첫알파벳이 다 대문자가 되어버림
-> Life Is Short, We Need Python
a.strip().replace('-',' ').lower().capitalize()
15. math라는 라이브러리에서
sqrt 함수와 factorial함수만 사용하고 싶을때 불러오는 방법은?
[답변] import math import sqrt, factorial
16. 1000을 167로 나누었을때의 몫과 나머지를 더한 값은?
[답변]
170
[코드]
a = 1000 // 167
b = 1000 % 167
a + b
17. 0부터 200까지 10간격으로 이루어진 객체 "a"를 생성하고
80 이하의 수만 b로 저장하시오
[답변]
a = np.linspace(0, 200, 21)
b = a[a <= 80]
혹은
a = list(range(0, 200, 10))
for i in range(len(a)) :
if a[i] < 8 :
b += a[i]
print(b)
18. input으로 받은 값은 어떤 데이터 타입으로 저장되는거
[답변] 문자형
### 19. 아래 문자열에 들어있는 단어를 보기 위해서는 어떤 코드를 입력해야 하는가
[문자열]
WezarezstudyingzPython
[코드]
a.replace('z', ' ')
혹은
a.split('z')
20. 아래 숫자들 중 8 보다 작은 숫자만 출력되도록 하세용
[4, 3, 8, 6, 9]
[답변]
a = [4, 3, 8, 6, 9]
b = []
for i in range(len(a)) :
if a[i] < 8 :
b += [a[i]]
print(b)
혹은
import numpy as np
a = np.array([4, 3, 8, 6, 9])
a[a<8]
21. " gOod$moRning "을
한문장만으로 'Good morning'으로 바꿔 출력하여라
[답변]
a = " gOod$morning"
" ".join(a.strip().lower().capitalize().split('$'))
number = "three"
day = 3
print("I ate {} apples. So I have sicked for {} days".format(number, day))
print("I ate {0} apples. So I have sicked for {1} days".format(number, day))
print("I ate {1} apples. So I have sicked for {0} days".format(number, day))
>
I ate three apples. So I have sicked for 3 days
I ate three apples. So I have sicked for 3 days
I ate 3 apples. So I have sicked for three days
number = "three"
day = 3
print(f"I ate {number}. apples. So I have sicked for {day} days")
>
I ate three. apples. So I have sicked for 3 days
# 이름과 나이를 입력받아서 출력하세요
names = input().strip()
age = input()
print(f"이름은 {names} 나이는 {age} 세 입니다")
>
박철수
20
이름은 박철수 나이는 20 세 입니다
# 1 - 20 까지 홀수만 모으고 싶다면
a = []
for i in range(20) :
if i % 2 != 0 :
a.append(i)
print(a)
# 구구단
for i in range(2, 10) :
for j in range(1, 10):
print(f"{i} X {j} = {i*j}")
print()

# 구구단 가로 출력
for z in range (2, 10) :
print(f"{z}단" , end="\t\t")
print()
for i in range(1, 10):
for j in range(2, 10) :
print(f"{j} x {i} = {j*i}", end='\t')
print()

1)
# 백준 10818번 : 최소, 최대
# 주어지는 N 개의 정수
n = int(input())
a = list(map(int, input().split()))
print(min(a), max(a))
> 입력
5
20 10 35 30 7
> 출력 예시
7 35
+)
# min, max 를 안쓰고?
n = int(input())
a = list(map(int, input().split()))
max0 = a[0]
min0 = a[0]
for i in a[1:]:
if i > max0:
max0 = i
elif i < min0:
min0 = i
print(min0, max0)
2)
# 2562번 최댓값
a = []
for i in range(9) :
a.append(int(input()))
print(max(a))
print(a.index(max(a))+1)
> 입력 예시
3
29
38
12
57
74
40
85
61
> 출력 예시
85
8
3)
# 1546 : 평균
# 시험 본 과목 갯수
N = int(input())
# 현재 성적
score = list(map(int, input().split()))
# 성적 중 최고점
score_m = max(score)
score_f = 0
for i in range(len(score)) :
score[i] = score[i]/score_m*100
score_f += score[i]
print(score_f / N)
> 입력 예시
3
10 20 30
> 출력 예시
66.66666666666667
4)
# 8958번 : OX퀴즈
# 테스트 갯수 t
t = int(input())
for i in range(t):
ox_list = input()
score = list(ox_list)
sum = 0
count = 1
for i in score:
if i == 'O':
sum += count
count += 1
else:
count = 1
print(sum)
> 입력 예시
3
OOXXOOXXOO
OXOXOXOXOXOXOX
OOOOOOOOOO
> 출력 예시
9
7
55
6)
# 4344 : 평균은 넘겠지
# 테스트 케이스 갯수 c
c = int(input())
for i in range(c):
student_score = list(map(int, input().split()))
avg = sum(student_score[1:])/student_score[0]
cnt = 0
for j in student_score[1:]:
if j > avg :
cnt += 1
# 나머지가 없어도 무조건 소수점 세자리까지 내려가야함
# print(round(cnt/student_score[0], 3)*100, "%")
print('%.3f' %(cnt/student_score[0]*100) + '%')
> 입력 예시
5
5 50 50 70 80 100
7 100 95 90 80 70 60 50
3 70 90 80
3 70 90 81
9 100 99 98 97 96 95 94 93 91
> 출력 예시
40.000%
57.143%
33.333%
66.667%
55.556%
7)
# 15596번 : 정수 N개의 합
def solve(a) :
hap = sum(a)
return hap
아니면 바로 리턴해도 된다
def solve(a) :
return sum(a)
8)
# 11654 : 아스키코드
A = input().strip()
print(ord(A))
9)
문제를 풀다보니 갑자기 min, max 함수가 작동하지 않는 일이 있었다.
TypeError: 'int' object is not callable
<에러 발생 원인>
해당 오류가 발생한 이유는 예약어를 변수명으로 사용 하였기 때문이였다. 예약어들은 각각의 기능들이 있는 함수이기 때문에 변수명으로 사용하면 안되는 것이다.
<해결법>
del을 이용하여 오류를 만든 변수를 삭제해준다.
ex) del max, min