Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write a code in python and no user defined modules A lazy student is attending a very basic math class! And sometimes laziness enables
Please write a code in python and no user defined modules
A lazy student is attending a very basic math class! And sometimes laziness enables people to find the quickest ways to get things done! Our student is given an arbitrary number of fractions, and the task is to find out the total sum of the fractions. And students in the class are allowed to get help from others to solve the problem. As you know, to add fractions with each other, one has to find the least common multiple of the denominators. The lazy student is not in the mood of calculating the least common multiple by hand! Your help is greatly needed by the lazy student to write a program, called gE2kylcm, to calculate the least common multiple of a bunch of numbers! Let's explore the problem to know how to develop gE2kylcm. The least common multiple (lcm) of two numbers can be calculated as: lcm(a,b)=gcd(a,b)a.b where gcd(a,b) is the greatest common divisor. This means, in order to calculate lcm of two numbers, you need to calculate their greatest common divisor (gcd) first. In order to find out the greatest common divisor of two numbers, you have to use the fact that: gcd(a,b)=gcd(b,r) where r is the remainder of the division of a/b. Therefore, for example, in order to find out gcd(99,36), by using this fact iteratively, you would have: gcd(99,36)=gcd(36,27)=gcd(27,9)=gcd(9,0). Hence, when the remainder gets zero, you would find out the gcd, which is 9 in this case. Now, that you learn about the algorithm of computing lcm it is time to develop gE2kylcm : - gE2kylcm first receives the number of denominators that you have to calculate their lcm. Let's call this number n which is always greater than 1 . - Subsequently, gE2kylcm receives the denominators in n separate lines. gE2kylcm assumes that the user only enters positive integers (greater than 0) in this step. - Finally, gE2kylcm will find out the least common multiple of all of the given numbers, and prints the result in a separate line. Note that you should only work with integers -and not floats- to avoid overflowError. In computing least common multiple (lcm), make sure you use "//" operator -and not not "/" operator- for division tasks. Two examples are shown in Table 5. In example 1, the user asked the program to compute the lcm of 5 numbers (18,6,3,9,1) and the result is printed as 18 . In example 2 the user asked the program to compute the lcm of 3 numbers (4,5,6) and the result is printed as 60 . Note that your program input and output format should be exactly the same as the format of the examples shown in Table 5 . You are not allowed to use any user-defined modules in developing gE2kylcm. Table 5: The gE2 kylcm Sample Inputs and OutputsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started