# Filename: factorial.py # Author: Brian L. Walter # Description of contents: # A simple program that computes factorials, demonstrating # the use of for loops. def main(): # Welcome the user. print ("\nI feel so free to compute factorials for your utter delight.") # Get the number to compute the factorial of. num = int(raw_input("\nPlease enter a nonnegative integer: ")) # Initialize fact, which accumulates the output value. fact = 1 # Multiply fact by the integers from 1 to the input value. for i in range(num): fact *= (i+1) # Print out the result. print str(num) + "! = " + str(fact) + ". " \ + "I feel special!" # Wait for the user to hit enter before exiting. raw_input("\nHit enter to exit.") main()