Question: Python 3.6- PROVIDE INDENTED SOURCE CODE . AND TXT FILES CREATED . Thanks Write a new Python program the implements Euclids algorithm for finding the

Python 3.6- PROVIDE INDENTED SOURCE CODE . AND TXT FILES CREATED . Thanks

Write a new Python program the implements Euclids algorithm for finding the Greatest Common Divisor. The algorithm for Euclid's method is given below.

The program should begin by asking the user whether input will be from the keyboard, or read from a file. If input is from the keyboard, the user is queried for two numbes and the Greatest Common Divisor is found. If input is from a file, the user is asked for a file name, and the file is opened and read. The input file format is to have two numbers on each line. The file may have many pairs of numbers; for each entered pair of numbers, the Greatest Common Divisor is found. When reading input from a file, the program should determine the number of input pairs from the file.

However the numbers are entered, for each pair of numbers, the program uses Euclids algorithm to find the Greatest Common Divisor. It then reports the number pair and their GCD both on the screen and by writing to an output file.

Your program should have a modular design. Include a function to perform Euclid's algorithm, and other code to handle input and output, and make a function call to the Euclid algorithm function. The input and output steps should use functions as appropriate, but you may design the modular breakdown.

Be sure your formal parameters and your actual parameters have different names within the source code. Also prepare your program to handle any unusal circumstances that you can foresee.

According to Wikipedia*, Euclids algorithm for finding the Greatest Common Divisor is one of the oldest known algorithms. Euclid did not invent the algorithm. It was well known in his day and he wrote about it in his book in 300 BC.

Here are the steps of the alogrithm. Given two numbers, to find the greatest common divisor of them both, divide the smaller one into the larger one using modular arithmetic and keep the remainder. Using the original remainder and original smaller number,observe that the remainder is the smaller of these two; the original smaller number will always be larger than the remainder.Use the remainder (now as the smaller number) and the original smaller number (now as the larger number), repeat the first step. Keep repeating until one of the two numbers is zero. The other number will be the greatest common divisor of the two original numbers.Symbolically, suppose you have two numbers, a and b. You wish to find the greatest common divisor of them. Ensure b is the smaller number. Thenalgorithm gcd(a, b) while b = 0

lett b let b a mod t let a t

return a.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!