Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions maths/factorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,13 @@

def factorial(number: int) -> int:
"""
Calculate the factorial of specified number (n!).
>>> import math
>>> all(factorial(i) == math.factorial(i) for i in range(20))
True
>>> factorial(0.1)
Traceback (most recent call last):
...
ValueError: factorial() only accepts integral values
>>> factorial(-1)
Traceback (most recent call last):
...
ValueError: factorial() not defined for negative values
>>> factorial(1)
1
>>> factorial(6)
720
>>> factorial(0)
1
Calculate the factorial of a non-negative integer.
:param n: non-negative integer
:return: factorial of n
:raises ValueError: if n is negative
"""
if number != int(number):
raise ValueError("factorial() only accepts integral values")
Expand Down
6 changes: 3 additions & 3 deletions strings/palindrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

def is_palindrome(s: str) -> bool:
"""
Return True if s is a palindrome otherwise return False.
Check whether a given string is a palindrome.

>>> all(is_palindrome(key) is value for key, value in test_data.items())
True
:param s: input string
:return: True if palindrome, False otherwise
"""

start_i = 0
Expand Down