12
Python – Making Decisions Lecture 02

Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these

Embed Size (px)

Citation preview

Python – Making Decisions

Lecture 02

Control StructuresA program that only has one flow is useful but limited. We can use if statements to make these decisions

If - Syntaxif (condition):

indented code block

Comparison OperatorsEqual toGreater than Less thanGreater than or equal toLess than or equal toNot equal to

==><>=<=!=

Else- SyntaxWhat if you want something to happen when the if condition is false?

If Else - Example

Checking for Multiple Conditions

We use an elif statement to check multiple conditions.

Elif - Example

Logic OperatorsCheck for multiple conditions in the same keyword.There are only three: and, or, not.

Precedence

You asleep yet?

Logic Example