Python3 Hcf
# Python3.x Python Highest Common Factor (HCF) Algorithm
[ Python3 Examples](#)
The following code is used to implement the Highest Common Factor (HCF) algorithm:
## Example (Python 3.0+)
# Filename : test.py# author by : www..com# Define a function def hcf(x, y): """This function returns the highest common factor of two numbers"""# Get the smaller number if x>y: smaller = y else: smaller = x for i in range(1,smaller + 1): if((x % i == 0)and(y % i == 0)): hcf = i return hcf# User input two numbers num1 = int(input("Enter first number: "))num2 = int(input("Enter second number: "))print("The HCF of", num1, "and", num2, "is", hcf(num1, num2))
Executing the above code produces the following output:
Enter first number: 54Enter second number: 24The HCF of 54 and 24 is 6
[ Python3 Examples](#)
YouTip