Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jtjun committed Dec 21, 2019
1 parent bb2a12d commit 76e6364
Show file tree
Hide file tree
Showing 36 changed files with 2,610 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*/.DS_Store
.DS_Store
__pycache__
.idea/
.vscode/
*.pyc
__pycache__/
~$
Binary file added day1/Lab-01-Basic Data Types.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions day1/codes/lab_1_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
P = float(input("원금을 입력하세요: "))
r = float(input("연이율을 입력하세요 (% 단위, 숫자만 입력): "))
n = int(input("만기까지의 기간을 입력하세요 (년): "))

A = (1 + r / 100) ** n * P

print("만기 금액은 " + str(A) + "입니다.")
5 changes: 5 additions & 0 deletions day1/codes/lab_1_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
today = int(input("오늘은 무슨 요일입니까? (월: 1 ~ 일: 7): "))
duration = int(input("며칠 뒤의 요일을 알고 싶습니까?: "))

future = (today + duration - 1) % 7 + 1
print("그 날의 요일은 " + str(future) + "입니다. (월: 1 ~ 일: 7)")
4 changes: 4 additions & 0 deletions day1/codes/lab_1_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
number = float(input("반올림할 수를 입력해 주세요: "))
rounded = int(number + ((number % 1) // 0.5))

print("반올림 결과는 " + str(rounded) + "입니다.")
10 changes: 10 additions & 0 deletions day1/codes/lab_1_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
hour = float(input("시침 값을 입력해주세요: "))
minute = float(input("분침 값을 입력해주세요: "))

hour_angle = hour * (360 / 12)
minute_angle = minute * (360 / 60)

hour_angle = hour_angle + minute / 60 * (360 / 12)

angle = (minute_angle - hour_angle) % 360
print("시침에 대한 분침의 각도는 " + str(angle) + "도입니다.")
12 changes: 12 additions & 0 deletions day1/codes/lab_1_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
count = 0

answer = int(input("71 + 42 = "))
count = count + int(answer == 71 + 42)

answer = int(input("153 + 188 = "))
count = count + int(answer == 153 + 188)

answer = int(input("321 + 1016 = "))
count = count + int(answer == 321 + 1016)

print("3개 중 " + str(count) + "개 맞았습니다.")
5 changes: 5 additions & 0 deletions day1/codes/lab_1_6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
r = int(input("색상 코드 1-2째 자리: "), 16)
g = int(input("색상 코드 3-4째 자리: "), 16)
b = int(input("색상 코드 5-6째 자리: "), 16)

print("R = " + str(r) + ", G = " + str(g) + ", B = " + str(b))
12 changes: 12 additions & 0 deletions day1/codes/lab_1_7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
korean = int(input("국어 점수: "))
math = int(input("수학 점수: "))
english = int(input("영어 점수: "))

length = (korean + 5) // 10
print('국어 ' + '#' * length + ' ' * (10 - length) + ' ' + str(korean))

length = (math + 5) // 10
print('수학 ' + '#' * length + ' ' * (10 - length) + ' ' + str(math))

length = (english + 5) // 10
print('영어 ' + '#' * length + ' ' * (10 - length) + ' ' + str(english))
Binary file added day2/Lab-02-Lists Conditionals Loops.pptx
Binary file not shown.
26 changes: 26 additions & 0 deletions day2/codes/bubbleSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
sort n elements
by bubble sort
"""

"""
아래 부분에
길이 n 을 먼저 input으로 받고
n 개의 숫자를 input으로 받아
list 를 만드세요.
"""
# code 시작


# code 끝

"""
아래 부분에 list 를
bubble sort 알고리즘으로
오름차순 정렬 후 출력하세요.
ex) [1, 2, 3, 4, 5]
"""
# code 시작


# code 끝
63 changes: 63 additions & 0 deletions day2/codes/hanoi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
tower of hanoi
"""
# 아래는 하노이 탑을 출력하기 위한 코드 입니다.
# 신경쓰지 않으셔도 됩니다. (수정하지 마세요.)
A = list()
B = list()
C = list()
hanoi = [A, B, C]
n = 0
def printHanoi():
for pole in range(3):
print(str(pole)+' '+str(hanoi[pole]))
# error check
for pole in range(3):
for i in range(len(hanoi[pole]) - 1):
if (hanoi[pole][i] < hanoi[pole][i + 1]):
print("\n잘못 이동 되었습니다.\n프로그램을 종료합니다.")
exit(0)

"""
아래 부분에 input을 받아
n 개의 원판이 있는 하노이 탑을 만드세요.
0 [n, n-1, ..., 2, 1]
1 []
2 []
꼴로 출력 되어야 합니다.
"""

# code 시작

# input 받기
n =

# n 부터 내림차순으로 A 기둥에 원판을 넣으세요.

# code 끝

# 하노이 탑 출력
printHanoi()

"""
기둥 이름 두 개를 input 으로 받아
첫 번째 기둥에서 두 번째 기둥으로
원판을 옮기는 과정을
모든 원판이 옮겨질 떄까지 반복하세요.
"""

# code 시작

while( ) : # B 기둥으로 모두 옮겨졌는지 확인
# 계속 진행

if( ) : # 적절한 input 인지 체크
printHanoi() # 매번 하노이 탑을 출력함
else : # 아니라면, 다음 input 받음
print("잘못된 입력 입니다.")

# 성공 메시지 출력
print("성공입니다!")

# 코드 끝
12 changes: 12 additions & 0 deletions day2/codes/snail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
snail n*n matrix
"""

# code 시작

# 크기 n 을 입력으로 받으세요.


# 달팽이 배열을 n * n 형태로 출력

# code 끝
15 changes: 15 additions & 0 deletions day2/codes/star.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
print n lines
diamond
"""

"""
아래 부분에 n 개 줄의
다이아몬드 모양을
print 하는 코드를 작성하세요.
"""
# code 시작



# code 끝
38 changes: 38 additions & 0 deletions day2/codes/ticTacToe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
tic-tac-toe
game
"""

# code 시작

# 3*3 board 를 표현할 수 있도록 변수 생성

# 생성한 board 출력
"""
첫 출력 시
0|1|2
3|4|5
6|7|8
로 나와야 합니다.
첫 출력 이후
모든 칸은 공백(' ') 으로
바꿔줍니다.
"""

# 아래 condition 은 게임이 끝났는지 아닌지 확인합니다.
condition = False
while(not condition): # condition 이 거짓인 동안 게임을 진행합니다.
# 'O' 와 'X' 를 번갈아 입력 받습니다.

# 받은 입력이 적절한지 확인합니다.
# (이미 마킹된 위치인지 확인)

# 현재 board 출력

# condition 을 업데이트 합니다. (게임이 끝났는지 아닌지 확인)

# code 끝

# 종료 메시지를 출력합니다.
print("게임 종료!")
40 changes: 40 additions & 0 deletions day2/samples/bubbleSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
sort n elements
by bubble sort
"""
"""
아래 부분에
길이 n 을 먼저 input으로 받고
n 개의 숫자를 input으로 받아
list 를 만드세요.
"""
# code 시작

n = int(input("배열 길이를 입력하세요. : "))

arr = list(range(n))
for i in range(n):
arr[i] = int(input(str(i+1)+"번째 원소 : "))

print("정렬 전")
print(arr)

# code 끝

"""
아래 부분에 list 를
bubble sort 알고리즘으로
오름차순 정렬 후 출력하세요.
ex) [1, 2, 3, 4, 5]
"""
# code 시작

for i in range(n):
for j in range(n-1-i):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]

print("정렬 후")
print(arr)

# code 끝
67 changes: 67 additions & 0 deletions day2/samples/hanoi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
tower of hanoi
"""
# 아래는 하노이 탑을 출력하기 위한 코드 입니다.
# 신경쓰지 않으셔도 됩니다. (수정하지 마세요.)
A, B, C = list(), list(), list()
hanoi = [A, B, C]
n = 0
def printHanoi():
for pole in range(3):
print(str(pole)+' '+str(hanoi[pole]))

# error check
for pole in range(3):
for i in range(len(hanoi[pole]) - 1):
if hanoi[pole][i] < hanoi[pole][i + 1]:
print("\n잘못 이동 되었습니다.\n프로그램을 종료합니다.")
exit(0)

"""
아래 부분에 input을 받아
n 개의 원판이 있는 하노이 탑을 만드세요.
0 [n, n-1, ..., 2, 1]
1 []
2 []
꼴로 출력 되어야 합니다.
"""
n = int(input("원판의 수를 입력하세요. : "))

# n 부터 내림차순으로 A 기둥에 원판을 넣으세요.
# A += list(range(n,0,-1))
for i in range(n):
A.append(n-i)
# 하노이 탑 출력
printHanoi()

"""
기둥 이름 두 개를 input 으로 받아
첫 번째 기둥에서 두 번째 기둥으로
원판을 옮기는 과정을
모든 원판이 옮겨질 떄까지 반복하세요.
"""

ans = A.copy()
# B 기둥으로 모두 옮겨졌는지 확인, 아니라면 계속 진행
while B != ans: # and C != ans:
fromPole = int(input("\n첫 번째 기둥 (0, 1, 2) : "))
toPole = int(input("두 번째 기둥 (0, 1, 2) : "))

# 적절한 input 인지 체크
if (fromPole in range(3)) and (toPole in range(3)):
if len(hanoi[fromPole]) < 1:
print("잘못된 입력 입니다.")
else:
# 적절한 input 이라면 옮김
block = hanoi[fromPole].pop()
hanoi[toPole].append(block)
# hanoi[toPole].append(hanoi[fromPole].pop())

# 매번 하노이 탑을 출력함
printHanoi()
else:
# 아니라면, 다음 input 받음
print("잘못된 입력 입니다.")

print("성공입니다!")
32 changes: 32 additions & 0 deletions day2/samples/snail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
sort n elements
by bubble sort
"""

n = int(input("크기를 입력하세요. : "))
snail = list()
for i in range(n):
snail.append([0]*n)
# left down right up
direc = [[0, 1], [1, 0], [0, -1], [-1, 0]]

d, i, j = 0, 0, 0
for m in range(1, n*n+1):
snail[i][j] = m
i += direc[d][0]
j += direc[d][1]
if (i not in range(n)) or (j not in range(n)) or (snail[i][j] != 0):
i -= direc[d][0]
j -= direc[d][1]
d = (d+1) % 4
i += direc[d][0]
j += direc[d][1]

# 달팽이 배열을 n * n 형태로 출력
lenn = len(str(n*n)) # n^2 의 자리수

for i in range(n):
line = ''
for j in range(n):
line += ' '*(lenn - len(str(snail[i][j]))) + str(snail[i][j]) + ' '
print(line)
Loading

0 comments on commit 76e6364

Please sign in to comment.