From 649f1cd71b2aebd2eacd598c23b63590289d4620 Mon Sep 17 00:00:00 2001 From: devxl Date: Thu, 24 Jan 2019 11:40:24 -0500 Subject: [PATCH] Wrote factorial function...fixed mixed parantheses bug --- factorial.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/factorial.py b/factorial.py index 3569741..b6232a7 100755 --- a/factorial.py +++ b/factorial.py @@ -8,16 +8,23 @@ def factorial(n): # TODO Define your logic for factorial here - return # TODO! + fact = 0 + if n == 1: + fact = 1 + else: + fact = factorial(n-1) * n + return fact # TODO! + def test_factorial(): assert factorial(1) == 1 # TODO: add more + 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) + print("Number of possible trial orders: " + str(norders))