From f76dcd8f4f5f025115c7ee4dc79aea76e4b0f8c7 Mon Sep 17 00:00:00 2001 From: ssdesroc <43478912+ssdesroc@users.noreply.github.com> Date: Thu, 24 Jan 2019 12:28:53 -0500 Subject: [PATCH] Update factorial.py Added factorial code and fixed bugs --- factorial.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/factorial.py b/factorial.py index 3569741..611e1a6 100755 --- a/factorial.py +++ b/factorial.py @@ -7,17 +7,23 @@ def factorial(n): - # TODO Define your logic for factorial here - return # TODO! + if n == 0: + return 1 + else: + return n*factorial(n-1) + def test_factorial(): assert factorial(1) == 1 - # TODO: add more + assert factorial(0) == 1 + assert factorial(2) == 2 + assert factorial(3) == 6 + 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 = 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))