Sure, here is a Python program to find the GCD (Greatest Common Divisor) of two numbers in Python:
Python
def gcd(a, b):
"""
Finds the greatest common divisor of two numbers.
Args:
a: The first number.
b: The second number.
Returns:
The greatest common divisor of the two numbers.
"""
if a < b:
a, b = b, a
while b != 0:
a, b = b, a % b
return a
if __name__ == "__main__":
a = 10
b = 20
gcd_value = gcd(a, b)
print(gcd_value)
This program works by first checking if the first number is less than the second number. If it is, then the program swaps the two numbers. Then, the program iterates through the numbers and keeps track of the remainder. The program breaks out of the loop when the remainder is 0. Finally, the program returns the first number.
To run the program, you can save it as a Python file and then run it from the command line. For example, if you save the program as
gcd.py, you can run it by typing the following command into the command line:
Code snippet
python gcd.py
This will print the GCD of the two numbers to the console.
Here is an example of the output of the program:
Code snippet
$ python gcd.py
10
As you can see, the output of the program is 10, which is the GCD of 10 and 20.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Sure, here is a Python program to find the GCD (Greatest Common Divisor) of two numbers in Python:
Python
This program works by first checking if the first number is less than the second number. If it is, then the program swaps the two numbers. Then, the program iterates through the numbers and keeps track of the remainder. The program breaks out of the loop when the remainder is 0. Finally, the program returns the first number.
To run the program, you can save it as a Python file and then run it from the command line. For example, if you save the program as
gcd.py, you can run it by typing the following command into the command line:Code snippet
This will print the GCD of the two numbers to the console.
Here is an example of the output of the program:
Code snippet
As you can see, the output of the program is 10, which is the GCD of 10 and 20.