Skip to content

Commit 3333d9b

Browse files
dalnkneptunius
authored andcommitted
fix ValueError to assert input is int first
1 parent e40c358 commit 3333d9b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

source/recursion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def factorial(n):
44
"""factorial(n) returns the product of the integers 1 through n for n >= 0,
55
otherwise raises ValueError for n < 0 or non-integer n"""
66
# check if n is negative or not an integer (invalid input)
7-
if n < 0 or not isinstance(n, int):
7+
if not isinstance(n, int) or n < 0:
88
raise ValueError('factorial is undefined for n = {}'.format(n))
99
# implement factorial_iterative and factorial_recursive below, then
1010
# change this to call your implementation to verify it passes all tests

0 commit comments

Comments
 (0)