In this Python challenge we will write two functions to calculate and return the Highest Common Factor (HCF) and the Lowest Common Multiple (LCM) of two numbers.
Highest Common Factor (HCF)
Note that the HCF is also known as the GCD (Greatest Common Divisor).
To calculate the HCF of two numbers we will write a function based on Euclid’s Division Algorithm. Your function called HCF() will take two parameters and will be based on the following flowchart:
Create the HCF() function on the Python trinket below:
Lowest Common Multiple
Once we have worked out the HCF of two numbers we can easily calculate their Lowest Common Multiple (LCM). The LCM of two numbers a and b is their product divided by their HCF:
LCM(a, b) = ab/HCF(a,b)
Your task is to create a new Python function called LCM() that takes two parameters a and b and returns the LCM of the two numbers using the above formula.
Use the following test plan to test both the HCF() and LCM() functions.
|Test #||Input Values||Expected Output||Actual Output|
Solution...The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area