Table of Contents
Python program to find HCF
Python program to find HCF : Highest Common Factor/GCD (Greatest Common Divisor) of two or more numbers is a highest integer which can divide them.
E.g. HCF of 12 and 18 is 6
Logic to find HCF in Python
def hcf(x, y):
z = x if x < y else y
hcf = 0
for i in range(1,z+1):
if((x % i == 0) and (y % i == 0)):
hcf = i
return hcf
#itvoyagers.in
a = int(input("Enter first number : "))
b = int(input("Enter second number : "))
c = hcf(a,b)
print("HCF of %d and %d is %d"%(a,b,c))
Output :
Enter first number : 12
Enter second number : 48
HCF of 12 and 48 is 12
———————————————–
Enter first number : 20
Enter second number : 48
HCF of 20 and 48 is 4
We are aiming to explain all concepts of python in easiest terms as possible.

ITVoyagers
Author
PRACTICALS/PRACTICE PROGRAM IN PYTHON
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on File Handling |
Easy quiz on file handling in python part 1 |
Easy quiz on file handling in python part 2 |
Quizzes on Exception Handling |
Easy quiz on Exception Handling in python part 1 |
Easy Quiz on Exception Handling in python part 2 |
Quizzes on Regular Expressions |
Easy Quiz on Regular Expression in python part 1 |
Quizzes on Python concepts coming soon… |
Python basic quiz |
New and easy python quiz basic part 1 |
New and easy python quiz (basic) part 2 |
New and easy python quiz (basic) part 3 |
Python practice quiz set |
Best Practice Quiz Set on Python Programming Part 1 |
Best Practice Quiz Set on Python Programming Part 2 |
Best Practice Quiz Set on Python Programming Part 3 |
Best Practice Quiz Set on Python Programming Part 4 |
Best Practice Quiz Set on Python Programming Part 5 |