Python – Making Decisions

12
Python – Making Decisions Lecture 02

description

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 decisions. If - Syntax. if (condition): indented code block. Comparison Operators. Equal to Greater than Less than - PowerPoint PPT Presentation

Transcript of Python – Making Decisions

Page 1: Python – Making Decisions

Python – Making Decisions

Lecture 02

Page 2: Python – Making Decisions

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

Page 3: Python – Making Decisions

If - Syntaxif (condition):

indented code block

Page 4: Python – Making Decisions

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

==><>=<=!=

Page 5: Python – Making Decisions

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

Page 6: Python – Making Decisions

If Else - Example

Page 7: Python – Making Decisions

Checking for Multiple Conditions

We use an elif statement to check multiple conditions.

Page 8: Python – Making Decisions

Elif - Example

Page 9: Python – Making Decisions

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

Page 10: Python – Making Decisions

Precedence

Page 11: Python – Making Decisions

You asleep yet?

Page 12: Python – Making Decisions

Logic Example