livepython.net

161. Python Program to Find the GCD and LCM of Two Numbers

MediumImport

Overview

Import one function with from ... import ... and call it by its own name.

Problem Statement

Read two whole numbers, one per line (both are 1 or more). Print their GCD (greatest common divisor: the biggest number that divides both) and their LCM (lowest common multiple: the smallest number both divide into). For example, for 12 and 18:

GCD: 6
LCM: 36

Import gcd with from math import gcd. The LCM is a * b // gcd(a, b).

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

Two whole numbers, one per line. Example:

12
18

Output

The output for that example:

GCD: 6
LCM: 36

The tests try 4 different inputs.

Learn this firstChapter 18 · Python Import: How to Use Modules
solution.py
# write your code here

EXPECTED OUTPUT

1GCD: 6
2LCM: 36

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.