How to program factorial in Python?

Computer Science
Tutor: None Selected Time limit: 1 Day

I don't get it :(((
Nov 22nd, 2014

# Python program to find the

# factorial of a number

# provided by the user

# take input from the user

num = int(input("Enter a number: "))

factorial = 1

# check if the number is negative, positive or zero

if num < 0:

  print("Sorry, factorial does not exist for negative numbers")

elif num == 0:

  print("The factorial of 0 is 1")

else:

  for i in range(1,num + 1):

  factorial = factorial*i

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

Reference:

http://www.programiz.com/python-programming/examples/factorial


Nov 22nd, 2014

Are you studying on the go? Check out our FREE app and post questions on the fly!
Download on the
App Store
...
Nov 22nd, 2014
...
Nov 22nd, 2014
Dec 3rd, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer