Hi Robert! Thanks for the heads up on the Style Guide. I'll read out the links you pointed out to me. About the script, result and Python Challenge, I apologize, however... in previous emails bigger pointers were given speaking about using 'maketrans' to solve the challenge. My way was a work around that I was trying to implement since day 1 and that can be (and maybe it will be) used as a base for a (non-serious) deciphering program.
So, again, I'm sorry for presenting too much information, however more important parts where said already and if people are willing to find out by searching a list/web instead of trying out by themselves... they are going to find it! Cheers! 2012/1/5 Robert Sjoblom <robert.sjob...@gmail.com>: > On 5 January 2012 19:41, Joaquim Santos <jsantos.la...@gmail.com> wrote: >> Hi List! > [...] >> This is my script (I know that I only verify a small range but it >> works for what I want for now...) >> >> import string >> >> def decrypt(cypheredText, shiftedCypherNumber): >> ''' >> This function will take two arguments. The first is the cyphered text, >> the second >> is the number of characters we need to shift the text so we can decrypt it. >> This is a Caesar cypher. >> ''' >> >> textTranslated = list() >> >> for letter in cypheredText: >> >> asciiValue = ord(letter) >> >> >> if asciiValue in range(97, 123): >> asciiValue += shiftedCypherNumber >> >> if asciiValue > 122: >> asciiValue -= 26 >> >> newLetter = chr(asciiValue) >> >> >> textTranslated.append(newLetter) >> >> joinedText = ''.join(textTranslated) >> >> return joinedText >> >> >> text = 'g fmnc wms bgblr rpylqjyrc gr zw fylb' >> >> a = decrypt(text, 2) >> >> print a >> >> and this is the end result: > > First of all, congratulations on solving it. Second, please don't > include the answer to any python challenges to this list as future > members or people searching for help with the same particular > challenge might not want to know the answer. Thirdly, I think you > should read PEP 8 - Style Guide for Python Code, but I'll quote the > absolutely most relevant part: >>Use blank lines in functions, sparingly, to indicate logical sections. > You don't need a blank line after every line of code; in fact, it > makes it harder to read. Where does one block end and another begin? > >>PEP 257 describes good docstring conventions. Note that most importantly, >>the """ that ends a multiline docstring should be on a line by itself, and >>preferably preceded by a blank line, > > def decrypt(cypheredText, shiftedCypherNumber): > '''This function will take two arguments. The first is the cyphered text, > the second is the number of characters we need to shift the text > so we can decrypt it. This is a Caesar cypher. > > ''' > textTranslated = list() > for letter in cypheredText: > asciiValue = ord(letter) > if asciiValue in range(97, 123): > asciiValue += shiftedCypherNumber > #and so on > > PEP 8 is really worth reading through: > http://www.python.org/dev/peps/pep-0008/ > there's also a link to PEP 257 in it. If you follow most of the > suggestions in PEP 8 it will be much easier to read your code, and > because of that easier to help you. > > -- > best regards, > Robert S. -- Joaquim Santos http://js-vfx.com linkedin _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor