Welcome folks today in this blog post we will be finding gcd or hcf of two numbers using while loop
in python. All the full source code of the application is shown below.
Get Started
In order to get started you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Python program to find GCD of two numbers using the while loop p, q = None, None # p & q - denotes the two positive numbers print ("-----Enter the two positive integer numbers-----") p = int (input ()) q = int (input ()) while p != q: if p > q: p -= q else: q -= p print ("\nThe GCD number is: ", p) |
Now if you execute the python
script by typing the below command as shown below
python app.py