[Tutor] base n fractional

Chris Castillo ctcast at gmail.com
Sun Apr 5 22:36:09 CEST 2009


I need some help converting the fractional (right side of the decimal) to
base 10.
I have this but it doesn't work

mynum = raw_input("Please enter a number: ")
myint, myfrac = mynum.split(".")
base = raw_input("Please enter the base you would like to convert to: ")
base = int(base)
mydecfrac = 0
fraclen = len(myfrac) - 1

for digit in range(len(myfrac) -1, -1, -1):
    mydecfrac = mydecfrac + int(myfrac[digit])
    mydecfrac = mydecfrac / base
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090405/612ca99f/attachment.htm>


More information about the Tutor mailing list