|
|
Here is the English translation:
In lines 1 through 5, we define the function factorial (factorial). The function body is located below the header and is written with the mandatory indentation.
In line 2, we check if n is greater than 1—block (3) of the algorithm. If it is, then in line 3, which is written with additional indentation, we set the function's result as n multiplied by the value of the factorial function (the same factorial function we are currently defining) for n minus 1 (4). At this point, the factorial function calls itself. Such a function is called a recursive function. If n is not greater than 1, then in line 5, we set the function's result equal to 1 (the condition for ending the recursion)—block (5).
In line 6 of the program, we use the input() function to read an integer (of type int) from the standard input (keyboard) and immediately store it in the variable n—block (2) of the algorithm.
In line 7, using the standard print() function, we print the result of the algorithm by calling the factorial() function—block (6).
