Question: Please write in Python. Although computers generally represent numbers as decimals, it is often convenient to express values as fractions. If we desire to convert
Please write in Python.
Although computers generally represent numbers as decimals, it is often convenient to express values as fractions. If we desire to convert a decimal to a fraction, we need to follow a two-step process . Starting with the number itself, multiply by ten repeatedly until no values remain after the decimal point. This is the numerator. Keep the multiplier as the denominator 2. Simplify the fraction. For instance, for 0.75: 1. Multiply by ten repeatedly: 0.75 x 10 x 10 75 Thus the numerator is 75 and the denominator is 10 x 10 2. Simplify the fraction: 100 1. Find the factors of the numerator and the denominator 75 -1,3,5, 25,75 1001,2, 4,5, 10, 20, 25, 50, 100 2. Find the greatest common factor of each and divide both by it 7525 3 00 25 4 0.75 Write a function factors( n) which accepts a number n and returns a list containing all of the factors of that number. (This is a common task. Write your own code-don't just google it!) Write a function fraction( n ) which accepts a decimal number n and retuns a tuple numerator, denominator) of the resulting fraction representation. Your submission should include two functions factors( n and fraction( n) def factors( n): pass def fractionn): n str str( n) decimal_part n str[ n_str.find+1: 1 # 1, Multiply by ten repeatedly (to make all of decimal positive) numern 10*?? denom??? # 2, Find factors numer factors? denom factors?? factor1 # ? ?? find greatest common factor of both numerator and denominator # ??? divide both by GCF before returning them return (numer,denom)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
