Advertisement
Guest User

Finding Factorial in Python

a guest
May 13th, 2012
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. inputNum = 5 #Number you would like to find the factorial
  2. i = 1 # i will be used as a counter
  3. total = 1 # this will be the total
  4. while i <= inputNum: # while i is less than or equal to inputNum
  5.     total = total * i # total is equal to total * i. ex: total*1; total*2; total*3; etc..
  6.     i = i + 1 # increments i each loop. adds 1 to i each time
  7. print "The factorial of " + str(inputNum) + " is: " + str(total) #prints the factorial of inputNum
  8. #str() simply converts an int into a String
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement