Question: Write a function that returns the least common factor of two integers. For example, if the integers were 24 and 32 the function would return

Write a function that returns the least common factor of two integers. For example, if the integers were 24 and 32 the function would return 2. The test suite is provided in the file below, but add further tests to ensure your function works. Add statements to the main program in the test program provided that prompt the user to enter two integers, the numerator and denominator of a fraction and reduce that fraction to its lowest form. For example, if the user enters 8 and 36 the program would print 2 and 9. (Of course, the normal way to simplify a fraction is to find the greatest common factor, not the least as we do here.) Make sure your program works for improper fractions and fractions in which either or both numerator and denominator are negative.

import sys def least_common_factor(num, denom): ''' return least common factor of num, denom ''' # # ============================================================================ # Test suite - do not change anything between this and the next marker comment # lines. # Functions for unit testing of function # def print_test(did_pass): ''' print particular test result''' linenum = sys._getframe(1).f_lineno if did_pass: print('Test at line '+str(linenum)+' ok.') else: print('Test at line '+str(linenum)+' FAILED.') def test_suite(): ''' test the winner function ''' print_test(least_common_factor(1, 2) == 1) print_test(least_common_factor(3, 12) == 3) print_test(least_common_factor(8, 16) == 2) print_test(least_common_factor(3, 17) == 1) print_test(least_common_factor(877, 1023) == 1) print_test(least_common_factor(36, 9) == 3) print_test(least_common_factor(3, -12) == 3) # Add more calls to properly test the function below this line. # ========================================================================= # # main # test_suite() # # Add statements to obtain numerator and denominator from user and to # simplify the fraction. 

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!