# [Tutor] Fwd: Re: fractions from Fractions

Alan Gauld alan.gauld at yahoo.co.uk
Tue Feb 6 04:53:14 EST 2018

```On 06/02/18 09:26, Alan Gauld via Tutor wrote:
> mail to the list.
>

> What input did you use and what output did you get?
>
> Input 239/30  --->  7 1 29
> Input 415/93  --->  4 2 6 7
>
> So far as I can tell your algorithm is correct, although
> I'm not sure why you limit it to values greater than 1?
>
> The problem suggests to do so and the wiki on Finite simple continued
> fractions showed examples also greater than one.  Upon consideration, i
> suppose that being greater than one is not a requirement but really is
> not of consequence to the insight I am seeking.

It depends on how the PyCharm "checker" works.
If it uses a test value less than 1 it will fail the test.

> But is it perhaps the format of the output that Pycharm
> objects to?
>
> No, the format required is for the elements of the list to appear on one
> line separated by a space.

Do you have the exact wording of the requirements?
Or even a url to the PyCharm site for this specific problem?

>> I think I know the source of the trouble.
> Would you like to tell us?
>
> My input is a string which I convert to num and den.  The problem ask
> specifically that the input format be "A line with an fraction in the
> "numerator/denominator" format and I am interpreting this to mean some
> kind of application of the Fraction module.  But that is just a wild
> guess and is what I was hoping I could get some insight on.

I don't think so, your conversion is doing the same job.

Personally I'd have used split() rather than finding
the index and slicing

num,den = [int(n) for n in fraction.split('/')]

But under the covers its doing much the same as your code.

>> I have tried importing fractions from Fraction
>
> And what happened?
>
> Not much.  I just bungled something:
> fraction = input(Fraction(numerator, denominator)

You would have needed something like

fraction = Fraction(input('>'))

Assuming Fraction has a string based constructor which
I don't think it does. I really don't think Fraction
helps you here.

>> while num > den and den != 0:

I'd let it handle numbers less than 1 by converting
the while loop:

while den > 0

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

```