[Tutor] Creating an Invalid Message for user

Steven D'Aprano steve at pearwood.info
Sat Apr 19 03:58:18 CEST 2014

```Hello Saba, and welcome,

code looks like this:

On Fri, Apr 18, 2014 at 10:19:52PM +0100, Saba Usmani wrote:

> print "Welcome to the binary and decimal converter"loop = Truewhile
> loop: bord = raw_input("Enter b for binary or d decimal or exit to
> exit") if bord == "b": d = 0 b = 0 factor = 1; b = raw_input ("Enter
> Binary Number:") b=b.lstrip("0") b = int(b) while(b > 0): if((int(b) %
> 10) == 1): d += factor b /= 10 factor = factor * 2 print "The Decimal
> Number is: ", d elif bord == "d": x=0 n=int(input('Enter Decimal
> Number: ')) x=n k=[] # array while (n>0): a=int(float(n%2))
> k.append(a) n=(n-a)/2 k.append(0) string="" for j in k[::-1]:
> string=string+str(j) print('The binary Number for %d is %s'%(x,
> string)) elif bord == "exit" : print "Goodbye" loop = False

A complete mess! Unfortunately, I have neither the time nor the
inclination to spend a lot of effort trying to unmangle the code to see
what you intended it to be.

As a programmer, you will often be dealing with text formats, and with
text it is very important that your email program (Outlook, it seems)
doesn't mess up the layout. Especially with Python. Unfortunately,
if your email program is configured to send so-called "Rich Text"
(actually HTML, exactly the same format that web pages use) a
side-effect is that it may mess up the layout as above.

I recommend that, when posting to technical forums like this tutor
mailing list, you turn off "Rich Text" posting so we can see the code
the way it is meant to be seen. If you help us to see your code the way