Created
April 3, 2017 07:54
-
-
Save Kcrong/08d15d396c8a8ee92d944b1119d8b595 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 random import shuffle | |
tags = ['a', 'b', 'c', 'result'] | |
def get_triangle_type(a, b, c): | |
if a == 90 or b == 90 or c == 90: | |
return "직각" | |
elif a > 90 or b > 90 or c > 90: | |
return "둔각" | |
elif a == b == c == 60: | |
return "정각" | |
else: | |
return "예각" | |
with open('tri_data.csv', 'w', encoding='utf8') as f: | |
for a in range(1, 179): | |
for b in range(1, 180 - a): | |
c = 180 - (a + b) | |
tri_type = get_triangle_type(a, b, c) | |
f.write('%d;%d;%d;%s\n' % (a, b, c, tri_type)) | |
with open('tri_data.csv', 'r', encoding='utf8') as f: | |
data = f.readlines() | |
shuffle(data) | |
with open('tri_data.csv', 'w', encoding='utf8') as f: | |
f.write(';'.join(tags) + '\n') | |
for line in data: | |
f.write(line) | |
""" | |
1 1 178 | |
1 2 1 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from random import shuffle
tags = ['a', 'b', 'c', 'result']
def get_triangle_type(a, b, c):
l = [a,b,c]
l.sort()
x, y, z = l[0],l[1],l[2]
if not(z < x+y):
return "삼각형아님"
zz = z2
xy = x2 + y**2
if zz == xy:
return "직각"
elif zz < xy::
return "예각"
else:
return "둔각"
with open('tri_data.csv', 'w', encoding='utf8') as f:
for a in range(1, 179):
for b in range(1, 180 - a):
c = 180 - (a + b)
tri_type = get_triangle_type(a, b, c)
f.write('%d;%d;%d;%s\n' % (a, b, c, tri_type))
with open('tri_data.csv', 'r', encoding='utf8') as f:
data = f.readlines()
shuffle(data)
with open('tri_data.csv', 'w', encoding='utf8') as f:
f.write(';'.join(tags) + '\n')
for line in data:
f.write(line)
"""
1 1 178
1 2 1
"""