728x90
https://www.codewars.com/kata/57a049e253ba33ac5e000212/train/python
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
7kyu 문제중 하나를 가져왔느데, 특별한 설명없이 그냥 팩토리얼을 만들라는거다
팩토리얼은 숫자 하나를 파라미터로 받으면, 그 숫자까지 다 곱해주면 된다.
ex) 5! = 5x4x3x2x1
이번엔 바로 직전 문제에서 배운 range안에 2개의 인자를 넣어서 해봤다.
def factorial(n):
result = 1
for num in range(1, n + 1):
result = result * num
return result
베스트 답변을 보니, math 라이브러리가 팩토리얼 정도는 지원해주는거 같다.
from math import factorial
print(factorial(5))
나머진 나랑 비슷한거 같다.
728x90
'알고리즘' 카테고리의 다른 글
[CodeWars] 6Kyu : Who likes it? (1) | 2024.12.06 |
---|---|
[CodeWars] 5Kyu : Directions Reduction (2) | 2024.12.05 |
[CodeWars] Multiplication table - 6Kyu (0) | 2024.12.05 |
[CodeWars] Simple Pig Latin- 5Kyu (1) | 2024.12.05 |
[CodeWars] Square Every Digit - 7Kyu (0) | 2024.12.05 |