Skip to content

Commit b5522d2

Browse files
author
John Dutchover
committed
handle factorial of zero
1 parent f40335f commit b5522d2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

app/routers/facts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ def random_fact(n: int) -> dict[int, str]:
3030

3131
@router.post("/fact_for_number")
3232
def fact_for_number(n: int) -> dict[int, str]:
33-
return random_fact(n)
33+
if n == 0:
34+
return {0: "The factorial of 0 is 1."}
35+
else:
36+
return random_fact(n)

0 commit comments

Comments
 (0)