본문 바로가기

Python Basics

[패스트캠퍼스 수강 후기] 파이썬 인강 자기계발 챌린지 6 회차 미션

패스트캠퍼스 파이썬 웹개발 올인원 패키지 후기(6)

 

벌써 패스트캠퍼스 파이썬 인강 웹개발 올인원 패키지 중 파이썬 기초 6번째 시간입니다.

지금까지 파이썬 설치 부터 데이터 타입, 조건문, 반복문 등을 배웠습니다.

어느정도 코딩을 할 수 있겠다는 자신감이 붙어 가는 것 같아요.

오늘은 반복문에 대해 좀 더 자세히 학습하고 복습하는 의미에서 퀴즈까지 풀어 보았습니다.

 

반복문

패스트 캠퍼스 파이썬 인강 시청중

# 시퀀스(순서가 있는)자료형 반복
# 시퀀스 자료형 : 문자열, 리스트, 튜플, 사전(dictionary), 집합(set)
# iterable 리턴 함수 : range, reversed, enumerate, filter, map, zip

print("## List 반복문 ##")
names = ['Son', 'Park', 'Ki', 'Lee', 'Kane', 'Messi']
for name in names:
    print('You are : ', name)
print()

print("## String 반복문 ##")
word = "dreams"
for c in word:
    print("Character : ", c)
print()

print("## Dictionary 반복문 ##")
my_info = {
    "name": "Kim",
    "age": 33,
    "city": "Seoul"
}
# 기본 값은 키
for key in my_info:
    print("my_info", key)
# 값
for key in my_info.values():
    print("my_info_values", key)
# 키
for key in my_info.keys():
    print("my_info_keys", key)
# 키, 값
for key in my_info.items():
    print("my_info_items", key)

print("## for 응용 ##")
name = "KennRY"
# 대문자는 소문자로, 소문자는 대문자로 변환해서 출력 하기
for n in name:
    if n.isupper():
        print(n.lower())
    else:
        print(n.upper())
    

<Output>

## List 반복문 ##
You are :  Son     
You are :  Park    
You are :  Ki      
You are :  Lee     
You are :  Kane    
You are :  Messi   

## String 반복문 ##
Character :  d     
Character :  r     
Character :  e
Character :  a
Character :  m
Character :  s

## Dictionary 반복문 ##
my_info name
my_info age
my_info city
my_info_values Kim
my_info_values 33
my_info_values Seoul
my_info_keys name
my_info_keys age
my_info_keys city
my_info_items ('name', 'Kim')
my_info_items ('age', 33)
my_info_items ('city', 'Seoul')
## Dictionary 반복문 ##
k
E
N
N
r
y

반복문 파이썬 인강 계속 시청 중

[break 구문]

# break
numbers = [14, 3, 4, 7, 10, 24, 17, 2, 33, 15, 34, 36, 38]

for num in numbers:
    if num == 33:
        print("Found : 33!")
    else:
        print("not found : 33!")
print()
for num in numbers:
    if num == 33:
        print("Found : 33!")
        break
    else:
        print("not found : 33!")
print()

[for - else 구문]

# for - else 구문(반복문이 정상적으로 수행 된 경우 else 블럭 수행)
# break에 걸리면 else 수행 안함, break에 안 걸리면 else 수행
for num in numbers:
    if num == 32:
        print("Found : 32!")
        break
    else:
        print("not found : 32!")
else:
    print("Not found 32......")
print()
print()

[continue 구문]

# continue
lt = ["1", 2, 5, True, 4.3, complex(4)]

for v in lt:
    if type(v) is float:
        continue # continue를 만나면 다음 구문을 생략하고 다음 반복문으로 넘어간다.
    print("타입 :", type(v))
print()

[iterable 자료구조 변환]

# iterable 자료 구조 변환
name = "Niceman"
print(reversed(name))
print(list(reversed(name)))
print(tuple(reversed(name)))

<Output>

not found : 33!
not found : 33!
not found : 33!
not found : 33!
not found : 33!
not found : 33!
not found : 33!
not found : 33!
Found : 33!
not found : 33!
not found : 33!
not found : 33!
not found : 33!

not found : 33!
not found : 33!
not found : 33!
not found : 33!
not found : 33!
not found : 33!
not found : 33!
not found : 33!
Found : 33!

not found : 32!
not found : 32!
not found : 32!
not found : 32!
not found : 32!
not found : 32!
not found : 32!
not found : 32!
not found : 32!
not found : 32!
not found : 32!
not found : 32!
not found : 32!
Not found 32......


타입 : <class 'str'>
타입 : <class 'int'>
타입 : <class 'int'>
타입 : <class 'bool'>
타입 : <class 'complex'>

<reversed object at 0x000002725B198E50>
['n', 'a', 'm', 'e', 'c', 'i', 'N']
('n', 'a', 'm', 'e', 'c', 'i', 'N')

조건문 반복문 복습(Quiz)

파이썬 인강 조건문,반복문 Quiz 풀이

# 1 ~ 5 문제 if 구문 사용
# 1. 아래 딕셔너리에서 '가을'에 해당하는 과일을 출력하세요.
q1 =  {"봄": "딸기", "여름": "토마토", "가을": "사과"}
print("1.", q1["가을"])

# 2. 아래 딕셔너리에서 '사과'가 포함되었는지 확인하세요.
q2 =  {"봄": "딸기", "여름": "토마토", "가을": "사과"}
print("2.", "사과" in q2.values())

# 3. 다음 점수 구간에 맞게 학점을 출력하세요.
# 81 ~ 100 : A학점
# 61 ~ 80 :  B학점
# 41 ~ 60 :  C학점
# 21 ~ 40 :  D학점
#  0 ~ 20 :  E학점
score = 77
if 81 <= score <= 100:
    print("3. A학점")
elif 61 <= score <= 80:
    print("3. B학점")
elif 41 <= score <= 60:
    print("3. C학점")
elif 21 <= score <= 40:
    print("3. D학점")
else:
    print("3. F학점")

# 4. 다음 세 개의 숫자 중 가장 큰수를 출력하세요.(if문 사용) : 12, 6, 18
nums = [12, 6, 18]
max = 0
for num in nums:
    max = num if num > max else max
print('4.', max)

# 5. 다음 주민등록 번호에서 7자리 숫자를 사용해서 남자, 여자를 판별하세요. (1,3 : 남자, 2,4 : 여자)
s = '891022-3473837'
if str(s[7]) in '13':
    print('5.', 'male')
elif str(s[7]) in '24':
    print('5.', 'female')
else:
    print('5.', 'alien')

# 6 ~ 10 반복문 사용(while 또는 for)

# 6. 다음 리스트 중에서 '정' 글자를 제외하고 출력하세요.
q3 = ["갑", "을", "병", "정"]
for q in q3:
    if q == "정":
        continue
    print('6.', q)

<Output>

1. 사과
2. True
3. B학점
4. 18
5. male
6. 갑
6. 을
6. 병

파이썬의 조건문, 반복문 까지 배웠습니다.

완벽히 마스터할때까지 반복 훈련이 중요할 거 같아요.

다음시간에도 남은 퀴즈를 풀면서 다시한번 복습 해보겠습니다.

읽어 주셔서 감사합니다!

 

패스트캠퍼스 파이썬 인강 자세한 내용은 아래 링크를 참고해 주세요!

 

https://bit.ly/2WG0IXN