Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Basics/Exercise/25_decorators/25_decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def check(f):
def helper(x):
if type(x) == int and x > 0:
if type(x) == int and x >= 0: #this should be >= to include 0 as well.
return f(x)
else:
raise Exception("Argument is not a non-negative integer")
Expand All @@ -10,21 +10,21 @@ def helper(x):

@check
def factorial(n):
if n == 1:
if n == 1 or n==0: #0!=1
return 1
else:
return n * factorial(n - 1)


for i in range(1, 10):
for i in range(10):
print(i, factorial(i))

try:
print(factorial(-1))
except Exception as e:
e.print_exception()
print(str(e))

try:
print(factorial(1.354))
except Exception as e:
e.print_exception()
print(str(e))