Implementation of the division algorithm in Python

<<algorithm

alg div en

x = float(input('x = '))
y = float(input('y = '))
if y == 0:
    print('Can not divide by 0')
else:
    z = x / y
    print('z =',z)

 

On line 1 of the program, we use the input function to read a floating-point number (type float) from the standard input (keyboard), which we immediately store in the variable x. The input function simultaneously displays the text provided as its argument on the screen. On line 2, we analogously ask the user to provide the second number, which we assign to the variable y.

The conditional statement on line 3 is the Decision block (3) from our algorithm. The statement checks whether y is equal to 0. If the condition is met, the print() instruction, written with an indentation on line 4, is executed (Input/Output block (4)). If the condition is not met, the instructions written with an indentation after the keyword else on line 5 are executed; in our case, these are the instructions on lines 6 and 7. First, on line 6, we assign the value of the quotient of x divided by y to the variable z (Operation block (5)), and then on line 7, we output the received result (Input/Output block (6)).

This is where our program ends. In Python, there is no separate instruction to indicate the program's termination.