Math, asked by lishanporwal512, 3 months ago


Write a Python program to display Factorial of a given number by user.

Answers

Answered by anindyaadhikari13
5

Required Answer:-

Question:

  • Write a Python program to display the factorial of a given number entered by the user.

Program:

This is an easy question. Read this post to get your answer.

Here comes the python program.

This can be done in two ways.

1. Using Loop:

# Written by @_mr_anindya_adhikari_

# Python program to find factorial of a number.

# take a number as input

n=int(input("Enter an integer number: "))

# Checking if number is negative.

if(n<0):

print("Invalid Input. Please try again layer")

else:

# Calculate Factorial

x=1

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

x*=i;

print("Factorial of the number is: ",x)

2. Without using Loop:

In this approach, we shall use math.factorial() function to find factorial of the number.

Note:- Factorial of any negative number or a decimal will give error.

Here is the program.

# Written by @_mr_anindya_adhikari_

# Python program to find factorial of a number.

# import math

import math

# take a number as input

n=int(input("Enter an integer number: "))

# Checking if number is negative.

if(n<0):

print("Invalid Input. Please try again layer")

else:

#now display the factorial

print("Factorial of the number is: ",math.factorial(n))

Output is attached.

Attachments:
Answered by Anisha5119
6

Answer:

Heya mate here's the answer Mark as brainliest pleaseeeeee follow up

Attachments:
Similar questions