I'm Electronic Engineer :)
[Do it] 점프 투 파이썬 - 2장 연습문제 code 본문
_________________________________________________________________________________________________________
Q 01.
kor = 80
eng = 75
mat = 55
avg = int((kor + eng + mat) / 3)
print("홍길동의 국어, 영어, 수학 점수의 평균은 {}점 입니다.".format(avg))
_________________________________________________________________________________________________________
-> 홍길동의 국어, 영어, 수학 점수의 평균은 70점 입니다.
_________________________________________________________________________________________________________
Q 02.
num = 13
if num % 2 :
print("홀수입니다.")
else :
print("짝수입니다.")
_________________________________________________________________________________________________________
-> 홀수입니다.
_________________________________________________________________________________________________________
Q 03.
pin = "881120-1068234"
yyyymmdd = pin[:6]
num = pin[7:]
print(yyyymmdd)
print(num)
_________________________________________________________________________________________________________
-> 881120
-> 1068234
_________________________________________________________________________________________________________
Q 04.
pin = "881120-1068234"
print("성별을 나타내는 숫자: {}".format(pin[7]))
_________________________________________________________________________________________________________
-> 성별을 나타내는 숫자: 1
_________________________________________________________________________________________________________
Q 05.
a = "a:b:c:d"
b = a.replace(':', '#')
print(b)
_________________________________________________________________________________________________________
-> a#b#c#d
_________________________________________________________________________________________________________
Q 06.
a = [1, 3, 5, 4 ,2]
a.sort()
a.reverse()
print(a)
_________________________________________________________________________________________________________
-> [5, 4, 3, 2, 1]
_________________________________________________________________________________________________________
Q 07.
a = ['Life', 'is', 'too', 'short']
result = ' '.join(a)
print(result)
_________________________________________________________________________________________________________
-> Life is too short
_________________________________________________________________________________________________________
Q 08.
a = (1, 2, 3)
a = a + (4,)
print(a)
_________________________________________________________________________________________________________
-> (1, 2, 3, 4)
_________________________________________________________________________________________________________
Q 09.
a = dict()
a[[1]] = 'python'
_________________________________________________________________________________________________________
-> TypeError: unhashable type: 'list'
-> # Key는 Immutable한 자료형만 가능하다.
_________________________________________________________________________________________________________
Q 10.
a = {'A':90, 'B':80, 'C':70}
result = a.pop('B')
print(a)
print(result)
_________________________________________________________________________________________________________
-> {'A': 90, 'C': 70}
-> 80
_________________________________________________________________________________________________________
Q 11.
a = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5]
aSet = set(a)
b = list(aSet)
print(b)
_________________________________________________________________________________________________________
-> [1, 2, 3, 4, 5]
_________________________________________________________________________________________________________
Q 12.
a = b = [1, 2, 3]
a[1] = 4
print(b)
_________________________________________________________________________________________________________
-> [1, 4, 3]
-> # a = b에서 얕은 복사가 이루어져서 a 변수와 b 변수가 가리키는 객체가 하나의 메모리 주소에 저장된 리스트로 동일하기 때문이다.
_________________________________________________________________________________________________________
'Study code & programming > Python' 카테고리의 다른 글
[Do it] 점프 투 파이썬 - 05일차 (0) | 2019.08.05 |
---|---|
[Do it] 점프 투 파이썬 - 04일차 (0) | 2019.08.05 |
[Do it] 점프 투 파이썬 - 03일차 (0) | 2019.08.05 |
[Do it] 점프 투 파이썬 - 02일차 (0) | 2019.08.03 |
[Do it] 점프 투 파이썬 - 01일차 (0) | 2019.08.01 |