[Tutor] Decimal Conversion

Michael Langford mlangford.cs03 at gtalumni.org
Mon Oct 15 20:36:47 CEST 2007


Use
b+=","+r
instead. That will add the , to the string named by b, and will concatenate
the string named by r to the end.

   --Michael

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

On 10/15/07, ddm2 at sfu.ca <ddm2 at sfu.ca> wrote:
>
> Hi,
>
> I'm new to Python, and found some problems on the internet that would be a
> good start to begin. The problem I have is that my conversion program
> (which
> currently only converts unsigned integers) also prints all these brackets
> and commas. Here is my code and the result:
> CODE:
> print ""
> print "--------------------"
> print "Unsigned Binary"
> print "--------------------"
> print ""
> n = int(raw_input("Please enter an integer: "))
> b = ''
> while n > 0:
>     r = n%2
>     n = n/2
>     b = r,b
> print b
>
> (ex: n = 15)
> RESULT:
> (1, (1, (1, (1, ''))))
>
> I think the problem is in the line of code 'b = r,b', but am not sure how
> to
> fix it. The tip given for the problem says I should 'append' r to b, but
> since b is not a list, 'b = r,b' was the only thing that came to my mind.
>
> Thanks in advance.
> _______________________________________________
> 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/3ae42692/attachment.htm 


More information about the Tutor mailing list