What are the two possible Boolean values? How are they represented in Python? →
Boolean values can be either true or false
In Python, these values are represented by the reserved words, True and False (notice that the initial letter is uppercase)
In Python, the type of these values is bool →
A Quick Aside on bool Types
If bool is the name of the type, what do you expect the name of the function to convert to this type is? →
== And =
What's the difference between == and =? →
== (double equals) is the equality operator
tests if the operand on left is equal to the operand on the right
also called logical equivalence
"foo" == "bar" →
= (equals) is the assignment operator
assigns the operand on the right to the variable on the left
sometimes called binding
a = "foo"
The Equality Operator
Some details about how == works:
two different types (except if they're both numeric), are never considered equal
two different numeric types can be equal
when comparing strings, case matters
A few examples:
"One" == "one"
1 = "1.0"
1 == "1"
1 == 1.0
If Statements
How do we construct an if statement? Why does indentation matter?
indentation signifies a block of code
the indented block of code immediately after the condition and colon will be executed if the condition is true
On Indentation
Um, BTW - how do we know when a block of code ends? →
no more lines
next line is back one level of indentation
This or That
What construct (keyword) would you used to execute a block of code only if the condition in the original if-statement is not met? What is the syntax for using it? →
Note that else will always have a corresponding if statement.
What's the Output? Part 1!
What's the output of this program? →
What's the Output? Part 2!
What is the output of this program if the user enters 'Yes', 'yes', and 'whatevs'? →
What's the Output? Part 3!
What happens if the user enters 16? →
…will this ever print 'yup, you got it!'? why? →
no, because it is always comparing a string to an int
Number Guessing Game
Create a game that →
hardcodes a "secret" number
asks the user to guess that secret number
prints out an appropriate message depending if the guess is correct (see 2 runs below)
A Possible Solution
A Few Terms
if statement header line and body:
One Last Pass
You can use the keyword pass to tell Python to do nothing. What do you think this prints out? →