Hacking Secret Ciphers with Python

(Ann) #1
Chapter 5 – The Reverse Cipher 69

Practice Exercises, Chapter 5, Section A


Practice exercises can be found at http://invpy.com/hackingpractice 5 A.


Summary


Now that we have learned how to deal with text, we can start making programs that the user can
run and interact with. This is important because text is the main way the user and the computer
will communicate with each other.


Strings are just a different data type that we can use in our programs. We can use the + operator
to concatenate strings together. We can use indexing and slicing to create a new string from part
of a different string. The len() function takes a string argument and returns an integer of how
many characters are in the string.


The Boolean data type has only two values: True and False. Comparison operators ==, !=, <,



, <=, and >= can compare two values and evaluate to a Boolean value.



Conditions are expression that are used in several different kinds of statements. A while loop
statement keeps executing the lines inside the block that follows it as long as its condition
evaluates to True. A block is made up of lines with the same level of indentation, including any
blocks inside of them.


A common practice in programs is to start a variable with a blank string, and then concatenate
characters to it until it “grows” into the final desired string.

Free download pdf