Hacking Secret Ciphers with Python

(Ann) #1

46 http://inventwithpython.com/hacking


Email questions to the author: [email protected]








Slicing is a simple way to get a “substring” from a larger string. (But really, a “substring” is still
just a string value like any other string.) Try typing the following into the shell:





myName = 'Zophie the Fat Cat'
myName[- 7 :]
'Fat Cat'
myName[:10]
'Zophie the'
myName[7:]
'the Fat Cat'





Practice Exercises, Chapter 4, Set B


Practice exercises can be found at http://invpy.com/hackingpractice4B.


Writing Programs in IDLE’s File Editor


Until now we have been typing instructions one at a time into the interactive shell. When we
write programs though, we type in several instructions and have them run without waiting on us
for the next one. Let’s write our first program!


The name of the software program that provides the interactive shell is called IDLE, the
Interactive DeveLopement Environment. IDLE also has another part besides the interactive shell
called the file editor.


At the top of the Python shell window, click on the File ► New Window. A new blank window
will appear for us to type our program in. This window is the file editor. The bottom right of the
file editor window will show you line and column that the cursor currently is in the file.

Free download pdf