Last active
December 23, 2018 08:22
-
-
Save anmolj7/04567e9ddc31386d418985917f08258a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Not using float because the we're multiplying not dividng, in multiplying, the end result will always be a whole number. | |
def factorial(number): | |
return 1 if number < 2 else number * factorial(number-1) | |
#Used number < 2 instead of number == 1 or number == 0, It's shorter. | |
try: | |
number = int(input("Enter A Number: ")) #Converting To Int cause we can find factorial | |
#of only integer and not decimal values .. | |
except ValueError: | |
#If the user types some other type of data, for example | |
#He enters string, we obviously can't find the factorial of string, | |
print("Please Enter A Valid Input.") | |
exit() | |
factorial(number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment