On Mon, Feb 4, 2013 at 6:52 PM, Ghadir Ghasemi
<ghasemm...@leedslearning.net> wrote:
> hi guys, this is the first bit of my program converting from binary to 
> decimal without use of built in functions.
>
> binnum = input("Please enter a binary number:  ")
> decnum = 0
> rank = 1
>
> for i in reversed(binnum):
>     decnum += rank * int(i)
>     rank *= 2
>     print(decnum).
>
> When I first tested the program, It printed the answer in a weird way. you 
> can see the print screen of first tirst in the attachment. I wanted to know 
> how I could adjust the program so that
> it only prints the real answer. e.g If user enters 11111111, then program 
> should only print 255.
> thank you.
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Move the print out of the loop.  Also, do not post screenshots, use
copy-paste.  So, this becomes:

binnum = input("Please enter a binary number: ")
decnum = 0
rank = 1

for i in reversed(binnum):
    decnum += rank * int(i)
    rank *= 2

print(decnum)

-- 
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to