To find HCF and LCM of two numbers in python, you have to ask from user to enter any two number to find and print the value of HCF and LCM as output as shown in the program given here.
Following python program ask from user to enter any two number to find and print HCF and LCM of the given two numbers:
# Python Program - Find HCF and LCM print("Enter 'x' for exit."); print("Enter two numbers to find HCF and LCM: "); num1 = input(); if num1 == 'x': exit(); else: num2 = input(); number1 = int(num1); number2 = int(num2); temp1 = number1; temp2 = number2; while temp2 != 0: t = temp2; temp2 = temp1%temp2; temp1 = t; hcf = temp1; lcm = (number1*number2)/hcf; print("HCF =",hcf); print("LCM =",lcm);
Here is the sample run of the above Python program shows how to find HCF and LCM of numbers:
Above is the initial output. Enter any two numbers say 8 and 20 as input and press enter key to find out the HCF and LCM value of the two numbers as shown in the below sample output:
Below is the same program with run on python shell:
You may also like to learn or practice the same program in other popular programming languages: