dimanche 20 mai 2018

Choose if your number is a fraction or a decimal

I'm trying to make it so if the denominator of the fraction is over 2, it prints the decimal. Else, it prints the fraction

from fractions import Fraction
z = float(input())
frac = (Fraction(z))
s = str(z)
x = s.find("/")
x1 = x + 1
segment = z[x1:]
print(segment)

if len(segment) <= 3:
    print(frac)
else:
    print(z)

Aucun commentaire:

Enregistrer un commentaire