From cb989cc0f52456e98192108569689dce50bc6d03 Mon Sep 17 00:00:00 2001 From: Vassiki Chauhan Date: Thu, 24 Jan 2019 11:42:26 -0500 Subject: [PATCH 1/3] modified factorial skeleton --- .idea/vcs.xml | 6 ++++++ factorial.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/factorial.py b/factorial.py index 3569741..87b1fc6 100755 --- a/factorial.py +++ b/factorial.py @@ -8,16 +8,21 @@ def factorial(n): # TODO Define your logic for factorial here - return # TODO! + if n == 1 or n == 0: + return 1 + else: + return n * factorial(n-1) + def test_factorial(): + # Tests the function with value 1 assert factorial(1) == 1 - # TODO: add more + 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: ") + 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)) From 2267a94f3d5fe48f2a17a83199bad6ff66a0d309 Mon Sep 17 00:00:00 2001 From: Vassiki Chauhan Date: Thu, 24 Jan 2019 11:56:59 -0500 Subject: [PATCH 2/3] fixed typos --- factorial.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/factorial.py b/factorial.py index 87b1fc6..6bb597a 100755 --- a/factorial.py +++ b/factorial.py @@ -7,7 +7,7 @@ def factorial(n): - # TODO Define your logic for factorial here + # Define your logic for factorial here if n == 1 or n == 0: return 1 else: @@ -21,8 +21,7 @@ def test_factorial(): 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 = int(input("Please enter number of conditions: ")) - norders = factorial(nconditions) - print("Number of possible trial orders: " + str(norders)) + # imported as a library, we should not run code below + conditions = int(input("Please enter number of conditions: ")) + orders = factorial(conditions) + print("Number of possible trial orders: " + str(orders)) From bba2dee24623554b1acda6766f582a903ae6a990 Mon Sep 17 00:00:00 2001 From: Vassiki Chauhan Date: Thu, 24 Jan 2019 12:01:10 -0500 Subject: [PATCH 3/3] added life changing blank line --- factorial.py | 1 + 1 file changed, 1 insertion(+) diff --git a/factorial.py b/factorial.py index 6bb597a..7d5460a 100755 --- a/factorial.py +++ b/factorial.py @@ -19,6 +19,7 @@ def test_factorial(): assert factorial(1) == 1 assert factorial(0) == 1 + if __name__ == '__main__': # This is a way to determine either file was "executed", so if it was # imported as a library, we should not run code below