Python Forum
Python Program to Find the Factorial of a Number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Program to Find the Factorial of a Number
#1
# Python program to find the factorial of a number provided by the user.

# change the value for a different result
num = 7

# To 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)
Yoriz write Nov-21-2022, 09:24 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Python Program to Find the Factorial of a Number - by elisahill - Nov-21-2022, 07:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Program to check whether a number is palindrome or not PythonBoy 18 3,121 Sep-12-2023, 09:27 AM
Last Post: PythonBoy
  Trying to find the next prime number FirstBornAlbratross 8 4,959 Aug-14-2023, 01:16 PM
Last Post: deanhystad
  Program that allows to accept only 10 integers but loops if an odd number was entered gachicardo 4 3,781 Feb-24-2022, 10:40 AM
Last Post: perfringo
  How to find the accuracy vs number of neighbours for KNN vokoyo 3 3,258 Apr-10-2019, 03:46 AM
Last Post: scidam
  Program that displays the number with the greatest amount of factors ilusmd 3 2,903 Nov-01-2018, 08:28 PM
Last Post: ichabod801
  Fork the process (factorial) vndywarhol 3 3,467 Sep-07-2018, 03:28 AM
Last Post: ichabod801
  Help on Creating Program to find the Median and Mode by hand EvanCahill 3 3,004 Jul-19-2018, 06:17 PM
Last Post: woooee
  python age calculator need to find the number of years before they turn 100 not using orangevalley 4 10,177 Mar-26-2018, 04:44 AM
Last Post: PyMan
  Program: count and find Truman 3 4,728 Feb-11-2018, 11:06 PM
Last Post: Larz60+
  how to find a next prime number? iamyourfather 2 6,601 Oct-01-2017, 04:21 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020