Home  >  Article  >  Backend Development  >  How to find the factorial of the input number in Python

How to find the factorial of the input number in Python

coldplay.xixi
coldplay.xixiOriginal
2021-03-09 16:33:3615444browse

Python method to find the factorial of the input number: first define a [factorial()] function and enter the factorial algorithm; then call the [factorial()] function to calculate the factorial of 5; finally use [print( )] function outputs the calculated result.

How to find the factorial of the input number in Python

The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.

Python method to find the factorial of the input number:

1. Create a new factorial .py to find the factorial of any number, as shown in the figure:

How to find the factorial of the input number in Python

2. Chinese coding statement annotation: # coding=gbk, as shown in the picture:

How to find the factorial of the input number in Python

3. Define a factorial() function. This function is used to calculate the factorial of the incoming parameters, as shown in the figure:

How to find the factorial of the input number in Python

4. Enter the factorial Algorithm, the code is as shown in the figure:

How to find the factorial of the input number in Python

5. Call the factorial() function to calculate the factorial of 5, as shown in the figure:

How to find the factorial of the input number in Python

6. Use the print() function to output the calculated results, as shown in the figure:

How to find the factorial of the input number in Python

7. Run the script and display Get the calculation results, as shown in the figure:

How to find the factorial of the input number in Python

Related free learning recommendations: python video tutorial

The above is the detailed content of How to find the factorial of the input number in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn