Skip to content

Instantly share code, notes, and snippets.

@MauricioDinki
Last active September 1, 2015 23:53
Show Gist options
  • Save MauricioDinki/d92dfcbb957278fd800c to your computer and use it in GitHub Desktop.
Save MauricioDinki/d92dfcbb957278fd800c to your computer and use it in GitHub Desktop.
Get the factorial of a number using python validations
#!/usr/bin/env python
# -*- coding: utf-8 -*-
factorial = 1
number = raw_input("Insert a number\n")
if number is '':
print("No ingresaste Nada")
elif number.isspace():
print("Insert some blank")
elif number.isalpha():
print("Words don't have factorial")
elif int(number) < 0:
print("Negative numbers don't have factorial")
elif int(number) is 0:
print("Factorial of 0 is 1")
else:
numberlimit = int(number) + 1
long(factorial)
for i in range(1, numberlimit):
factorial = factorial * i
print("The factorial of %s is %s")%(number,factorial)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment