Challenge 1: Find the Greatest Common Divisor
Given two numbers, find their greatest common divisor.
We'll cover the following
Problem Statement
Implement a function that takes two numbers, testVariable1
and testVariable2
and returns their greatest common divisor.
What is the Greatest Common Divisor?
Greatest Common Divisor of two or more integers is the largest positive integer that divides each of the integers.
For example, take two numbers and .
can be completely divided by , , , , , , and .
can be completely divided by , , , , , , and .
Therefore the greatest common divisor of and is .
Input
Two variables testVariable1
and testVariable2
containing numbers.
Output
The greatest common divisor of testVariable1
and testVariable2
.
Sample Input
6, 9
Sample Output
3
Try it Yourself
Try to attempt this challenge by yourself before moving on to the solution. Good luck!
def gcd(testVariable1, testVariable2) :# Write your code herereturn None
Let’s have a look at the solution review of this problem.