Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

b. Determine the number of dependent variables, p. Pg45

Answered: 1 week ago