diff --git a/factorial.py b/factorial.py index 3569741..80397f7 100755 --- a/factorial.py +++ b/factorial.py @@ -7,17 +7,23 @@ def factorial(n): - # TODO Define your logic for factorial here - return # TODO! + final_answer = 1 + for i in range(n): + product = n - i + final_answer *= product + return final_answer + def test_factorial(): assert factorial(1) == 1 - # TODO: add more + assert factorial(3) == 6 + assert factorial(6) == 720 + 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: ") + nconditions = int(input("Please enter number of conditions: ")) norders = factorial(nconditions) - print("Number of possible trial orders: " + str(norders) + print("Number of possible trial orders: " + str(norders))