Question: I was wondering how to convert a decimal into a fraction in its lowest form in Python.

For example:

```
0.25  -> 1/4
0.5   -> 1/2
1.25  -> 5/4
3     -> 3/1

```

Answer: 
```
from fractions import Fraction

print(Fraction(0.25))
print(Fraction(0.5))
print(Fraction(1.25))
print(Fraction(3))

#1/4
#1/2
#5/4
#3

```
This is how to do it simple and properly.

**By using Fraction:**

```
from fractions import Fraction
decimals = [0.25, 0.5, 1.25, 3, 0.6, 0.84]

for d in decimals:
    print(Fraction(str(d))) #Cast as string for proper fraction

```

**By using Decimal:**

```
from  decimal import Decimal
decimals = [0.25, 0.5, 1.25, 3, 0.6, 0.84]

for d in decimals:
    d = Decimal(str(d)) #Cast as string for proper fraction
    nominator,denominator = d.as_integer_ratio()
    if denominator==1:
        print(a)
    else:
        print(nominator,denominator, sep="/")

```

**Output:**

```
1/4
1/2
5/4
3
3/5
21/25

```