Python 3 Script to Find GCD or HCF of two Numbers Using For Loop Full Project For Beginners

Python 3 Script to Find GCD or HCF of two Numbers Using For Loop Full Project For Beginners

 

Welcome folks today in this blog post we will be finding gcd or hcf of two numbers using for 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

 

# taking first number
num1 = int(input("Enter first number: "))         
# taking second number      
num2 = int(input("Enter second number: "))              
 
gcd = 1
 
# finding GCD
for i in range(min(num1,num2),0,-1):                    
    if (num1%i) == 0 and (num2%i) == 0:
        gcd = i
        break
    
# printing GCD
print("The GCD of the two numbers is ", gcd)

 

See also  Python 3 Script to Compress PDF File on Command Line With Progressbar Using GhostScript Library Full Project For Beginners

 

Now if you execute the python script by typing the below command as shown below

 

python app.py

 

 

 

Leave a Reply