[Codewars] Sine, cosine and others
▶ 문제 : 사인, 코사인, 탄젠트, 코탄젠트를 구하라 - value로 사인값이 주어진다. - list 안에 [ sin(사인), cos(코사인), tan(탄젠트), cot(코탄젠트) ] 값을 넣어 리턴하라. - 조건1) 모든 숫자는 2 demical place까지 반올림하라 (round) - 조건2) 탄젠트 or 코탄젠트 값을 계산할 수 없을 때는 리스트 안에 포함시키지 말 것. test.describe('Basic tests') test.assert_equals(sctc(1),[1, 0.0, 0.0]) test.assert_equals(sctc(1/2),[0.5, 0.87, 0.58, 1.73]) test.assert_equals(sctc(3 ** 0.5 / 2),[0.87, 0.5, 1.73, 0.5..
[Codewars] Product of consecutive Fib numbers
▶ 문제 : ▶ 내 답안 : def F(n) : a, b = 0, 1 for i in range(n): a, b = b, a+b return a def productFib(prod): answer = [] n = 0 while True : r_1 = F(n) r_2 = F(n+1) if r_1*r_2 > prod : return [r_1, r_2, False] if r_1*r_2 == prod : return [r_1, r_2, True] n += 1 ▶ 모범답안 : def productFib(prod): a, b = 0, 1 while prod > a * b: a, b = b, a + b return [a, b, prod == a * b] ▶ 배워야할 부분 : while 문