Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FactorialError(Exception): pass
- class NegativeNumberError(FactorialError): pass
- class NotAnIntegerError(FactorialError): pass
- def factorial(number):
- """find the factorial of an integer."""
- if number < 0:
- raise NegativeNumberError, 'Negative Number has no factorial'
- if int(number) <> number:
- raise NotAnIntegerError, 'Only intergers have factorial'
- if number == 0:
- return 1
- else:
- return number * factorial(number - 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement