Last active
March 28, 2017 12:30
-
-
Save dohvis/cd83a5101e63a2452b579ce81ae05b3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define triangle's type | |
ACUTE = 0 | |
RIGHT_ANGLED = 1 | |
OBTUSE = 2 | |
FAIL = 3 | |
def classify_triangle(x, y, z): | |
if z >= (x + y): | |
return FAIL | |
x2, y2, z2 = map(lambda a: a ** 2, [x, y, z]) | |
if z2 < x2 + y2: | |
return ACUTE | |
elif z2 > x2 + y2: | |
return OBTUSE | |
else: | |
return RIGHT_ANGLED | |
if __name__ == "__main__": | |
x = int(input("x=")) | |
y = int(input("y=")) | |
z = int(input("z=")) | |
if not(x <= y <= z): | |
print('[-] Input rule: x <= y <= z') | |
import sys; sys.exit(1) | |
print(classify_triangle(x, y, z)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
month_list = list(range(1, 13)) | |
# 4로 나누면 윤년, 100으로 나눠지면 윤년 X, 400으로 나눠지면 윤년 | |
def get_month_day(month): | |
return { | |
1: 31, | |
2: 28, | |
3: 31, | |
4: 30, | |
5: 31, | |
6: 30, | |
7: 31, | |
8: 31, | |
9: 30, | |
10: 31, | |
11: 30, | |
12: 31, | |
}[month] | |
week_day = { | |
0: '월', | |
1: '화', | |
2: '수', | |
3: '목', | |
4: '금', | |
5: '토', | |
6: '일', | |
} | |
input_year, input_month, input_day = map(lambda x: int(x), input('년 월 일 입력(2017/03/28): ').split('/')) | |
print(input_year, input_month, input_day) | |
day = 0 | |
for year in range(1, input_year + 1): | |
for month in range(1, input_month + 1): | |
day += get_month_day(month) | |
print(day) | |
print(week_day[day % 7]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def harmonic_series(begin, n): | |
k = range(begin, n + 1) # 1 ~ 100 | |
real_value = sum(1.0/x for x in k) | |
measurement_value = math.log(n + 1) | |
print((real_value - measurement_value) / real_value) | |
begin = 1 | |
for n in range(1, 100): | |
harmonic_series(begin, n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
def is_prime(p): | |
n = int(sqrt(p)) | |
# print('n: %d' % n) | |
ret = True | |
for i in range(2, n + 1): | |
if p % i == 0: | |
ret = False | |
return ret | |
def eratos_filter(p): | |
n = int(sqrt(p)) | |
num_list = list(range(n)) | |
for i in num_list: | |
for j in range(2, i): | |
if i % j | |
p = int(input('> ')) | |
eratos_filter(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment