[Tutor] fractions from Fractions

Steven D'Aprano steve at pearwood.info
Mon Feb 5 04:57:10 EST 2018


Hi Rex,

My comments below.


On Sun, Feb 04, 2018 at 11:11:23PM -0500, Rex Florian via Tutor wrote:

> I have written a program to generate the array that describes the 
> finite simple continued fraction from any fractional input.  The input 
> is any fraction, num/den, and the output is the array.  The program 
> works and I am happy with the work.

Have you tried it with a proper fraction, like 1/2 or 4/11? As continued 
fractions, they ought to print out:

0 2        # 1/2 = 0 + 1/2
0 2 1 3    # 4/11 = 0 + 1/(2 + 1/(1 + 1/3))

but it doesn't.

 
> The problem is one of the PyCharm problems and when I use the check 
> feature it tells me my answer is incorrect.

I'm afraid I have no idea what you are talking about. What are the 
PyCharm problems, and what's "check feature"?


> I think I know the source 
> of the trouble.  The problem asks that my input format be "A single 
> line with an fraction in the numerator/denominator format.

Is it possible that you are supposed to write a function?

def contfract(fraction):
    # code as before


And then call it like this?


frac = input("Enter a fraction like num/den ")
contfract(frac)




-- 
Steve


More information about the Tutor mailing list