|
|
In line 1 of the program, we use the input() function to read an integer (of type int) from the standard input (keyboard), which we immediately store in the variable n. The input() function simultaneously displays the text provided as its argument on the screen. Line 1 implements the input/output operation contained in block (2) of the algorithm. The START block (1) does not have a direct equivalent in the Python language.
In lines 2 and 3, we declare the variables i and s, simultaneously assigning them initial values (equal to 1 in both cases) (3).
The while statement in line 4 is the equivalent of the selection block (4) of our algorithm. The instructions, written with the mandatory indentation in Python, contained in lines 5-6 (block 5) will be executed as long as the condition in the while statement is met, meaning as long as i is less than or equal to n. When the constantly incremented i becomes greater than n, we proceed to the instructions after the while loop, starting in line 7, where the result is printed (6) using the standard print() function.
This is where our program ends. The Python language does not have a separate instruction indicating the termination of the program.
