Conditionals

Controlling Program Flow w/ Conditionals

A conditional allows a decision to be made about which code path to take.

What do you think the two possible values are for boolean values?

The bool Type

Python represents these boolean values using the bool type. The bool type has two possible values:

Some things to pay attention to…

Boolean Expressions / The Equality Operator

A boolean expression is just an expression that eventually evaluates to a boolean value.

The equality operator, == (double equals), will test the left and right hand sides for equality and evaluate to the appropriate boolean value

if Statements

We use if statements to conditionally execute code.

For example:

if True:
	print("this is")
	print("true")

if Statements continued

This will also work with equality operators and variables

x = 5
y = 5
if x == y:
	print("x and y are equal")

Let's Make a Game!

Let's try making a number guessing game. Here's the expected output:

Guess the number that I'm thinking of
>5
you got it!

Review