Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 25_decorators.py #253

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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))