diff --git a/.pytest_cache/README.md b/.pytest_cache/README.md new file mode 100644 index 0000000..bb78ba0 --- /dev/null +++ b/.pytest_cache/README.md @@ -0,0 +1,8 @@ +# pytest cache directory # + +This directory contains data from the pytest's cache plugin, +which provides the `--lf` and `--ff` options, as well as the `cache` fixture. + +**Do not** commit this to version control. + +See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information. diff --git a/.pytest_cache/v/cache/lastfailed b/.pytest_cache/v/cache/lastfailed new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.pytest_cache/v/cache/lastfailed @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/.pytest_cache/v/cache/nodeids b/.pytest_cache/v/cache/nodeids new file mode 100644 index 0000000..ac8b7cd --- /dev/null +++ b/.pytest_cache/v/cache/nodeids @@ -0,0 +1,3 @@ +[ + "factorial.py::test_factorial" +] \ No newline at end of file diff --git a/__pycache__/factorial.cpython-36-PYTEST.pyc b/__pycache__/factorial.cpython-36-PYTEST.pyc new file mode 100644 index 0000000..a65b553 Binary files /dev/null and b/__pycache__/factorial.cpython-36-PYTEST.pyc differ diff --git a/factorial.py b/factorial.py index 3569741..abaedd9 100755 --- a/factorial.py +++ b/factorial.py @@ -7,17 +7,22 @@ def factorial(n): - # TODO Define your logic for factorial here - return # TODO! + prod = 1 + for i in range(n): + prod = prod * (n - i) + return prod + def test_factorial(): assert factorial(1) == 1 - # TODO: add more + assert factorial(4) == 24 + assert factorial(0) == 1 + if __name__ == '__main__': # This is a way to determine either file was "executed", so if it was # imported (by e.g. pytest) as a library, we should not run code # below - nconditions = raw_input("Please enter number of conditions: ") - norders = factorial(nconditions) - print("Number of possible trial orders: " + str(norders) + nconditions = input("Please enter number of conditions: ") + norders = factorial(int(nconditions)) + print("Number of possible trial orders: " + str(norders))