doctest python

Solutions on MaxInterview for doctest python by the best coders in the world

showing results for - "doctest python"
Jayson
26 Jan 2018
1python -m doctest -v filename.py 
Alejandra
25 Feb 2019
1"""
2This is the "example" module.
3
4The example module supplies one function, factorial().  For example,
5
6>>> factorial(5)
7120
8"""
9
10def factorial(n):
11    """Return the factorial of n, an exact integer >= 0.
12
13    >>> [factorial(n) for n in range(6)]
14    [1, 1, 2, 6, 24, 120]
15    >>> factorial(30)
16    265252859812191058636308480000000
17    >>> factorial(-1)
18    Traceback (most recent call last):
19        ...
20    ValueError: n must be >= 0
21
22    Factorials of floats are OK, but the float must be an exact integer:
23    >>> factorial(30.1)
24    Traceback (most recent call last):
25        ...
26    ValueError: n must be exact integer
27    >>> factorial(30.0)
28    265252859812191058636308480000000
29
30    It must also not be ridiculously large:
31    >>> factorial(1e100)
32    Traceback (most recent call last):
33        ...
34    OverflowError: n too large
35    """
36
37    import math
38    if not n >= 0:
39        raise ValueError("n must be >= 0")
40    if math.floor(n) != n:
41        raise ValueError("n must be exact integer")
42    if n+1 == n:  # catch a value like 1e300
43        raise OverflowError("n too large")
44    result = 1
45    factor = 2
46    while factor <= n:
47        result *= factor
48        factor += 1
49    return result
50
51
52if __name__ == "__main__":
53    import doctest
54    doctest.testmod()
55
queries leading to this page
m doctest in pythondoctests in pythonwhat is the correct way to run all doctests in pythonsimple program for doctest in pythonwrite python doctestdoctest syntax pythonwhat is a doctest pythonpython define doctestrun all doctests in pythonhow to doctest pythonwrite a doctest pythonpython howto doctestpython call doctestpython3 run doctestscorrect way to run doctest in pythonrun doc test in pythonrunning doctest pythonpython run all doctestsdoctest command line pythonpython3 doctestswhat is doctest in pythoncorrect way to write doctest in pythonpython m doctestedoctest methods python doctest pythonhow to run doctestin pythonpython doctests command line examplepython doctest in command linerun a doctest in command line pythonpython doctests command linepython doctestspython execute doctestpython run doctestrun doctest in python3what is a correct method to run a doctest in pythonpython doctest programizrun all doctests pythonhow doctest work in pythonpython run all doctests from command linehow to run all doctest in pythondoctest in pythonrunning doctests in pythondoctest pyhtonpython commandline doctestwhat is way of run all doctest in pythondoctest command python3python doctest examplecommand to run doctest in pythonwhat is the way to run all the doctest in pythonwhat is the correct way to write doctest in pythonpython doctest runcorrect way to run all doctest in pythonpthon doctest 28 29import doctest pythonwhat is the correct way to run all the doctest in pythondoctest pythopython command line doctestspython doctest command linepython 3 run doctestsdoctest python examplesrun doctests in command line pythonrunning all doctests in pythonwhy we use doctest in pythonpython correct way to run doctestdoctest tutorial pythonwhat is a python doctestwhy do we need a doctest in pythonpython3 doctestdoctest python runpyhon doctesthow to write a doctest pythonrun all doctest in pythondoctest python executeright way to run all doctests in pythondoctest in python syntaxdoctests python command linecorrect way to write a doctest pythonpython m doctesthow to run doctests in python filewhat is the correct way to run doctest in pythondoctest python examplerun doctests pythonrunning doctests pythonhow to run doctests in python command linerun doctest from command line python3python doc testwriting a doctest in pythonpython doctest to modulecommand line python run doctestdoctest python command linerun doctest in pythondoctests pythonpython doctestwhat is doctests in pythonwhat is the correct way to write a doctest in pythondoctest python whatrun python doctestrun doctest python command linepython run all the doctestsrun doctest pythonpython doctest stepsdoctest python correct way to runpython correct way to write a doctestdoctest pythonwhat is a doctest in pythonhow to run a doctest in pythonpython run doctestspython how to run doctestrun all the doctests pythonhow to run doctest in pythonhow to run doctests in pythonway to run doctest pythonpython correct way to run all doctestspython doctest usagehow to run all doctests in pythonpython write doctestpython run doctests command linepython run doctests syntaxcorrect way to write doctests in pythondoctest python commanddoctest python correct waypython run doctest commandpython doctest commanddoctest command pythonwhat is the correct way to write a doctest pythonrun doctests python command linedoctest module in pythondoctest python