carmichael_number - add doctests
diff --git a/maths/carmichael_number.py b/maths/carmichael_number.py
index 81712520ffc7..08b5c70e8fe7 100644
--- a/maths/carmichael_number.py
+++ b/maths/carmichael_number.py
@@ -10,10 +10,21 @@
 Examples of Carmichael Numbers: 561, 1105, ...
 https://en.wikipedia.org/wiki/Carmichael_number
 """
+
 from maths.greatest_common_divisor import greatest_common_divisor
 
 
 def power(x: int, y: int, mod: int) -> int:
+    """
+
+    Examples:
+    >>> power(2, 15, 3)
+    2
+
+    >>> power(5, 1, 30)
+    5
+    """
+
     if y == 0:
         return 1
     temp = power(x, y // 2, mod) % mod
@@ -24,15 +35,47 @@ def power(x: int, y: int, mod: int) -> int:
 
 
 def is_carmichael_number(n: int) -> bool:
-    b = 2
-    while b < n:
-        if greatest_common_divisor(b, n) == 1 and power(b, n - 1, n) != 1:
-            return False
-        b += 1
-    return True
+    """
+
+    Examples:
+    >>> is_carmichael_number(562)
+    False
+
+    >>> is_carmichael_number(561)
+    True
+
+    >>> is_carmichael_number(5.1)
+    Traceback (most recent call last):
+         ...
+    ValueError: Number 5.1 must instead be a positive integer
+
+    >>> is_carmichael_number(-7)
+    Traceback (most recent call last):
+         ...
+    ValueError: Number -7 must instead be a positive integer
+
+    >>> is_carmichael_number(0)
+    Traceback (most recent call last):
+         ...
+    ValueError: Number 0 must instead be a positive integer
+    """
+
+    if n <= 0 or not isinstance(n, int):
+        msg = f"Number {n} must instead be a positive integer"
+        raise ValueError(msg)
+
+    return all(
+        power(b, n - 1, n) == 1
+        for b in range(2, n)
+        if greatest_common_divisor(b, n) == 1
+    )
 
 
 if __name__ == "__main__":
+    import doctest
+
+    doctest.testmod()
+
     number = int(input("Enter number: ").strip())
     if is_carmichael_number(number):
         print(f"{number} is a Carmichael Number.")

### Describe your change:

Contributes to  #9943
Added doctests.

* [x] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?

### Checklist:
* [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
* [x] This pull request is all my own work -- I have not plagiarized.
* [x] I know that pull requests will not be merged if they fail the automated tests.
* [x] This PR only changes one algorithm file.  To ease review, please open separate PRs for separate algorithms.
* [x] All new Python files are placed inside an existing directory.
* [x] All filenames are in all lowercase characters with no spaces or dashes.
* [x] All functions and variable names follow Python naming conventions.
* [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html).
* [x] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing.
* [x] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
* [x] If this pull request resolves one or more open issues then the description above includes the issue number(s) with a [closing keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue): " #ISSUE-NUMBER - 9943".
