-1
>>> From fractions import Fraction

>>> f=Fraction(2/6)
>>> f
Fraction(6004799503160661, 18014398509481984)

it gives some unexpected result ? why

Guy
  • 46,488
  • 10
  • 44
  • 88
Randy
  • 79
  • 6
  • 1
    What did you expected it to give? – Guy Jul 18 '19 at 09:54
  • 1
    Possible duplicate of [Fractions in Python for floating point numbers](https://stackoverflow.com/questions/52893643/fractions-in-python-for-floating-point-numbers) – Georgy Jul 18 '19 at 09:57
  • Also: [Float to Fraction conversion in Python](https://stackoverflow.com/questions/38172252/float-to-fraction-conversion-in-python) – Georgy Jul 18 '19 at 09:58

2 Answers2

1

If you want to get the result of that fraction, use: f.__float__()

Roman
  • 146
  • 5
1

you have to use , instead / for fraction

from fractions import Fraction

f=Fraction(2,6)
print(f)
shubham
  • 503
  • 2
  • 14