On 06.02.2018 10:53, Alan Gauld via Tutor wrote:

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.

Oh, most certainly it has - though it may accept more forms of input than the OP needs/wants:

>>> from fractions import Fraction
>>> Fraction('2/3')
Fraction(2, 3)
>>> Fraction('2.3')
Fraction(23, 10)
>>> Fraction('2e-3')
Fraction(1, 500)
>>>

Since fractions is pure Python it may also be instructive to study its source:
https://github.com/python/cpython/blob/master/Lib/fractions.py

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to