Question: IN PYTHON Purpose The purpose of this assignment is to give you practice with writing functions and for loops. Problem In Mathematics, the greatest common

Purpose The purpose of this assignment is to give you practice with writing functions and for loops. Problem In Mathematics, the greatest common divisor (GCD) of two or more integers, when at least one of them is not zero, is the largest positive integer that divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4. In arithmetic and number theory, the least common multiple, of two integers a and b, usually denoted by LCM(a,b), is the smallest positive integer that is divisible by both a and b. You cannot use any library functions for GCD or LCM, you must write these functions on your own. Example of LCM: What is the LCM of 4 and 6 ? Multiples of 4 are: 4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76, Multiples of 6 are 6,12,18,24,30,36,42,48,54,60,66,72, Common multiples of 4 and 6 are simply the numbers that are in both lists 12,24,36,48,60,72, So, from this list of the first few common multiples of the numbers 4 and 6, their LCM is 12 . Write a program that accepts 2 integers from the user in the main function and calls a function to compute the GCD of the two numbers. The parameters to the function are the two integers. The result (GCD) is returned as a function retum value. After printing the GCD, a function is called to compute the LCM of the two numbers and the result (LCM) is returned as a function retum value of the second function. For this lab you are given some starter code, which is just a template of hov the fimction definitions need to be made and how the "main "function is recognised. The program consists of 2 Py thon files: nain.py defines the starting/entry point of the program and ged km.py is the file containing fiunctions. Download this starter code from Canras and fill it in. Keep in mind that the file main py is the part of the program which show syou where the "main" function is where it sarts execuition. As discussed in class the concept of a "main" function is the part of the program which will be exccuted first. In your starter program, everything that you code under the if statement: if name =manmain. is considered to be the main function (simplistically speaking) - The main function prompts the user to enter 2 positive integers. If anything other than positive integers are entered, display an error message and ask them to re-enter 2 numbers (you will need to use a while loop to keep acoept input if they are invalid). - With a valid a set of inputs are valid, call the function to compute GCD (pass the two integers as arguments), result is retumed via function return value. - Print the GCD result in the main function - Call the second function to compute LCM (pass the two integers as arguments), result is returned via function return value. - Print the LCM result in the main function. - Stop the program (there is no need to continuously accept numbers) Your function MUST use a for loop to compute the GCD of the two numbers and return the result as a function return value. You can use any kind of logic you want to compute the LCD of two numbers (except any library function that directly computes the LCD of two numbers). The results of the computation MUST be printed in the main function. No global variables ean be used the program, all variables used must be "local" to each function. Inputs Only one set of inputs are sufficient for program completion as long as they are valid inputs, meaning th you do not have to keep looping once a set of inputs have been processed Comments For this assignment, make sure that you include your name in both the main py and ged lem py files, an that each function includes conments that explain what it does. You will also need comments within the "main" if statement denoting where inputs are collected and where the functions are called Sample Outputs Example 1: Entor a positive integer. Enter another positive integer, in ged=41cm=24 Example 2: Enter a positive integer, 12 Enter another positive integer: Bnter=4 ged=4 1cm=264 Fxample 3: Rnter a posieive integer. Entor anotbar positive integet. gged=3 len63 Example 4: Sncer a pobitive integor. in= BRAPDR: Input must be positite integors. Enter a positive integer. Fncerianother popitive integer. Birosit Input mast be positive integers. Enter a posirive integer. Enter another pooitive integer. 1cm=2059
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
