Skip to content
This repository was archived by the owner on Oct 2, 2021. It is now read-only.

Commit 4ffec36

Browse files
committed
2018-04-28
1 parent 64a535a commit 4ffec36

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

Chapter.3/Practice/1_if.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'''
2+
다음 코드의 결과값은 무엇일까?
3+
'''
4+
5+
a = "Life is too short, you need a python"
6+
7+
if "wife" in a : print("wife")
8+
elif "pyton" in a and "you" not in a : print("python")
9+
elif "shirt" not in a : print("shirt")
10+
elif "need" in a : print("need")
11+
else : print("none")
12+
13+
# shirt

Chapter.3/Practice/2_while.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
while문을 이용하여 아래와 같이 별(*)을 표시하는 프로그램을 작성해 보자.
3+
*
4+
**
5+
***
6+
****
7+
*****
8+
'''
9+
10+
i = 0
11+
12+
while True :
13+
i += 1
14+
if i > 5 : break
15+
print('*' * i)

Chapter.3/Practice/3_for.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
A 학급에 총 10명의 학생이 있다. 이 학생들의 중간고사 점수는 다음과 같다.
3+
[70, 60, 55, 75, 95, 90, 80, 80, 85, 100]
4+
for문을 이용하여 A 학급의 평균 점수를 구해 보자.
5+
'''
6+
7+
A = [70, 60, 55, 75, 95, 90, 80, 80, 85, 100]
8+
9+
total = 0
10+
11+
for score in A :
12+
total += score
13+
14+
average = total / len(A)
15+
16+
print(average)

Chapter.3/예제/14.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 리스트 안에 for문 포함하기
2+
3+
a = [1, 2, 3, 4]
4+
result = []
5+
for num in a :
6+
result.append(num * 3)
7+
print(result) # [3, 6, 9, 12]
8+
9+
# 리스트 내포를 이용한 간단한 해결 방식
10+
result = [num * 3 for num in a]
11+
print(result) # [3, 6, 9, 12]
12+
13+
# 짝수에만 3을 곱하여 담고 싶다면
14+
result = [num * 3 for num in a if num % 2 == 0]
15+
print(result) # [6, 12]
16+
17+
# 구구단의 모든 결과에 리스트에 담기
18+
result = [x * y for x in range(2, 10) for y in range(1, 10)]
19+
print(result)

Chapter.4/예제/1.py

Whitespace-only changes.

0 commit comments

Comments
 (0)