Made this for my trig-bundle program, which I'm converting to TI-BASIC soon:
Code:
Code:
def decToFrac():
value = float(input("Enter a decimal value: "))
integer = int(value)
value -= integer
repFracArray = []
while value != 0:
value = 1 / value
currentValue = int(value)
if currentValue >= 1000:
break
value -= currentValue
repFracArray.append(currentValue)
numerator = 1
denominator = repFracArray.pop(-1)
while len(repFracArray) > 0:
numerator += repFracArray.pop(-1) * denominator
ph = numerator
numerator = denominator
denominator = ph
numerator += integer * denominator
print(str(numerator) + '/' + str(denominator))