m2skills

factorial python

May 31st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. # program to find factorial of a number using loops
  2.  
  3. def factorial(number):
  4.     fact = 1
  5.     while number != 0:
  6.         fact = fact * number
  7.         number = number - 1
  8.    
  9.     return fact
  10.    
  11. # main function
  12. cont = True
  13. while cont:
  14.     number = int(input("Enter the number : "))
  15.     answer = factorial(number)
  16.     print("Factorial of " + str(number) + " is " + str(answer) )
  17.     n = int(input("Do you want to continue (1/0) : "))
  18.     if n == 0:
  19.         cont = False
  20.     print()
Add Comment
Please, Sign In to add comment