[Tutor] binary translator
Alan Gauld
alan.gauld at btinternet.com
Sun Dec 16 01:03:32 CET 2007
"2face xzibit" <kuffert_med_hat at hotmail.com> wrote
> ...f you have any comments on the source code please let me know
I'll add a few.
> def ChooSe():
Its kind of conventional to have function names start lowercase
and use uppercase for classes. Not a rule but it helps when
code includes both to know wwhat the names refer to...
> kN = ('n','N','no','nah')
> if xit in kN:
You could cover more options by just checking for the
first letter being in 'nN':
if xit[0] in 'nN'
> chartobinary = {
> 'A' : '01000001',
> 'B' : '01000010',
> ...
> '9' : '00111001',
wow!
There are usually easier ways to create these kinds of lists
programmatically. Unless you have invented your own encoding
of course! - I didn't check...
> def TransLate():
> TransLate()
> ChooSe()
> ChooSe()
Calling ChooSe repeatedly like this is not a good idea,
it could run into the recursion limit. You would be better
to restructure the code to use a loop.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list