Python program to compute the GCD of two numbers.

Krishna Priya. N
3 min readJun 5, 2021

This Blog is definitely going to help you ,If you are in search of a python program to compute the GCD of two numbers.

What is GCD ?

The greatest common divisor (GCD), also called the greatest common factor, of two numbers is the largest number that divides them both. For instance, the greatest common factor of 20 and 15 is 5, since 5 divides both 20 and 15 and no larger number has this property. The concept is easily extended to sets of more than two numbers: the GCD of a set of numbers is the largest number dividing each of them.

Concepts Involved :

What is if…else statement in Python?

Decision making is required when we want to execute a code only if a certain condition is satisfied.

The if…elif…else statement is used in Python for decision making.

Syntax of if Statement

if test expression:
statement(s)

Here, the program evaluates the test expression and will execute statement(s) only if the test expression is True.

If the test expression is False, the statement(s) is not executed.

In Python, the body of the if statement is indicated by the indentation. The body starts with an indentation and the first unindented line marks the end.

Python interprets non-zero values as True. None and 0 are interpreted as False.

Python if Statement Flowchart

Return statement in Python :

A return statement is used to end the execution of the function call and “returns” the result (value of the expression following the return keyword) to the caller. The statements after the return statements are not executed. If the return statement is without any expression, then the special value None is returned.

Note: Return statement can not be used outside the function.

Syntax of return Statement

def fun():
statements
.
.
return [expression]

To further proceed with this experiment ,lets’s get to know about function in python and its syntax .

What is a function in Python?

In Python, a function is a group of related statements that performs a specific task.

Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable.

Furthermore, it avoids repetition and makes the code reusable.

Syntax of Function

def function_name(parameters):
"""docstring"""
statement(s)

Python Code to find the GCD of two numbers :

Output:

REFERENCE LINK:

To know more about Python ,Login GUVI

--

--