Hacking Secret Ciphers with Python

(Ann) #1

80 http://inventwithpython.com/hacking


Email questions to the author: [email protected]




  1. print('You have a lot of eggs. Gross!')




  2. else:




  3. print('Eat ALL the eggs!')




When you run this program, the integer 12 is stored in the variable numberOfEggs. Then the
condition numberOfEggs < 4 is checked to see if it is True. If it isn’t, the execution skips
the block and checks numberOfEggs < 20. If it isn’t True, execution skips that block and
checks if numberOfEggs == 144. If all of these conditions have been False, then the
else block is executed.


Notice that one and only one of these blocks will be executed. You can have zero or more
elif statements following an if statement. You can have zero or one else statements, and the
else statement always comes last.


The in and not in Operators


An expression of two strings connected by the in operator will evaluate to True if the first
string is inside the second string. Otherwise the expression evaluates to False. Notice that the
in and not in operators are case-sensitive. Try typing the following in the interactive shell:





'hello' in 'hello world!'
True
'ello' in 'hello world!'
True
'HELLO' in 'hello world!'
False
'HELLO' in 'HELLO world!'
True
'' in 'Hello'
True
'' in ''
True
'D' in 'ABCDEF'
True





The not in operator will evaluate to the opposite of in. Try typing the following into the
interactive shell:





'hello' not in 'hello world!'
False
'ello' not in 'hello world!'
False




Free download pdf