Made this for my trig-bundle program, which I'm converting to TI-BASIC soon:

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))
Before you do, try the code I put in your other post. That way you're not wasting space doing something the OS already does.

https://www.cemetech.net/forum/viewtopic.php?p=284972
Nomkid wrote:
Before you do, try the code I put in your other post. That way you're not wasting space doing something the OS already does.

https://www.cemetech.net/forum/viewtopic.php?p=284972


Will make sure to try what you posted!
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement