Question
Converting a decimal to a fraction Although computers generally represent numbers as decimals, itis often convenient to express values as fractions. If we desire toconvert
Converting a decimal to a fraction
Although computers generally represent numbers as decimals, itis often convenient to express values as fractions. If we desire toconvert a decimal to a fraction, we need to follow a two-stepprocess:
Starting with the number itself, multiply by ten repeatedlyuntil no values remain after the decimal point. This is thenumerator. Keep the multiplier as the denominator.
Simplify the fraction.
For instance, for 0.75:
1) Multiply by ten repeatedly:
0.75×10×10=75
Thus the numerator is 75 and the denominatoris 10×10=100
2)Simplify the fraction:
Find the factors of the numerator and thedenominator.
75?{1,3,5,25,75}
100?{1,2,4,5,10,20,25,50,100}
Find the greatest common factor of eachand divide both by it.
75÷25=3
100÷ 25 =4
0.75?3/4
Can you fill in the ??? in Python. Just the ???def factors( n ): passdef fraction( n ): n_str = str( n ) decimal_part = n_str[ n_str.find( '.' )+1: ] # 1. Multiply by ten repeatedly (to make all of decimal positive). numer = n * 10 ** ??? denom = ??? # 2. Find factors. numer_factors = ??? denom_factors = ??? factor = 1 # ??? 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
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