please help me i am stuck,
here is my code:
def recursive_factorial (n):
if n == 0:
return 1
else:
return n *recursive_factorial(n-1)
def iterative_factorial (n):
product = 1
for i in range(1,n + 1):
product = product * i
return product
this is the assignment i am doing:
Create both a recursive function called recursive_factorial and iterative function called iterative_factorial that does the following
Accepts as parameter an Integer n
Computes the factorial of n
Returns the factorial of n
this is the test i am using:
import unittest
class RecursiveTestCase(unittest.TestCase):
def test_recursive_factorial_one(self):
result = recursive_factorial(4)
self.assertEqual(result, 24, msg="Inaccurate value")
def test_recursive_factorial_two(self):
result = recursive_factorial(0)
self.assertEqual(result, 1, msg="Inaccurate value")
def test_iterative_factorial_one(self):
result = iterative_factorial(5)
self.assertEqual(result, 120, msg="Inaccurate value")
def test_iterative_factorial_two(self):
result = iterative_factorial(0)
self.assertEqual(result, 1, msg="Inaccurate value")
this is the error i am getting:
Total Specs: 4 Total Failures: 21
.
test_iterative_factorial_oneFailure in line 21, in test_iterative_factorial_one
self.assertEqual(result, 120, msg=“Inaccurate value”)
AssertionError: Inaccurate value
2
.
test_iterative_factorial_twoFailure in line 25, in test_iterative_factorial_two
self.assertEqual(result, 1, msg=“Inaccurate value”)
AssertionError: Inaccurate value
What might be the problem? please help me…