Hacking Secret Ciphers with Python

(Ann) #1

20 http://inventwithpython.com/hacking


Email questions to the author: [email protected]


going back to the previous chapters. Or email your programming questions to the author at
[email protected].


Line Numbers and Spaces


When entering the source code yourself, do not type the line numbers that appear at the beginning
of each line. For example, if you see this in the book:



  1. number = random.randint(1, 20)

  2. spam = 42

  3. print('Hello world!')


...then you do not need to type the “ 1 .” on the left side, or the space that immediately follows it.
Just type it like this:


number = random.randint(1, 20)
spam = 42
print('Hello world!')


Those numbers are only used so that this book can refer to specific lines in the code. They are not
a part of the actual program. Aside from the line numbers, be sure to enter the code exactly as it
appears. This includes the letter casing. In Python, HELLO and hello and Hello could refer to
three different things.


Notice that some of the lines don’t begin at the leftmost edge of the page, but are indented by four
or eight spaces. Be sure to put in the correct number of spaces at the start of each line. (Since each
character in IDLE is the same width, you can count the number of spaces by counting the number
of characters above or below the line you’re looking at.)


For example, you can see that the second line is indented by four spaces because the four
characters (“whil”) on the line above are over the indented space. The third line is indented by
another four spaces (the four characters “if n” are above the third line’s indented space):


while spam < 10:
if number == 42:
print('Hello')


Text Wrapping in This Book


Some lines of code are too long to fit on one line on the page, and the text of the code will wrap
around to the next line. When you type these lines into the file editor, enter the code all on one
line without pressing Enter.

Free download pdf