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.
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:
2. Chinese coding statement annotation: # coding=gbk
, as shown in the picture:
3. Define a factorial() function. This function is used to calculate the factorial of the incoming parameters, as shown in the figure:
4. Enter the factorial Algorithm, the code is as shown in the figure:
5. Call the factorial()
function to calculate the factorial of 5, as shown in the figure:
6. Use the print() function to output the calculated results, as shown in the figure:
7. Run the script and display Get the calculation results, as shown in the figure:
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!