Python procedure for Factorial (using while loop)


#------------------------------------------------
# Factorial function:
#    Input:  n
#    Output:  n!
#
def factorial (n):
	if (n <= 1):
		return 1

	i = 1
	product = 1
	while (i <= n):
		product = product * i
		i = i + 1

	return product

#------------------------------------------------
# Main program:
#    (execution starts at the first statement below)
#
get_number = 1

while (get_number == 1):
	x = input ("Enter a number:")
	if (x < 0):
		print "Invald number"
	else:
		get_number = 0

print "The factorial of", x, "is", factorial(x)