[Tutor] Decimal Conversion

Michael Langford mlangford.cs03 at gtalumni.org
Tue Oct 16 00:56:49 CEST 2007


>Michael has already explained that this is building
>a tuple of tuples. But you want to create strings.
>So first convert r to a string using str(r)

Yeah sorry about that....read some java over the weekend (source code to
http://reprap.org)...and then munged some of its syntactic sugar into the
python area of my brain. Python does not support that operation for +

      --Michael
-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.TierOneDesign.com/

On 10/15/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> <ddm2 at sfu.ca> wrote
>
> > print ""
> > print "--------------------"
> > print "Unsigned Binary"
> > print "--------------------"
> > print ""
>
> You don;t need the empty quotes to print a newline.
>
> In fact the whole of the above is easier done using triple quotes
>
> print """
> --------------------
> Unsigned Binary
> --------------------
> """
>
> It has nothing to do with your problem but for future reference...
>
> To the real issue:
>
> > n = int(raw_input("Please enter an integer: "))
> > b = ''
>
> so n is an integer and b is a string.
>
> > while n > 0:
> >    r = n%2
> >    n = n/2
> >    b = r,b
>
> Michael has already explained that this is building
> a tuple of tuples. But you want to create strings.
> So first convert r to a string using str(r)
> Now you can append using the plus operation for strings
>
> b = r+b
>
> or just
>
> b += r
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071015/387398b6/attachment-0001.htm 


More information about the Tutor mailing list