Download - Python – Making Decisions
Transcript
![Page 1: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/1.jpg)
Python – Making Decisions
Lecture 02
![Page 2: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/3.jpg)
If - Syntaxif (condition):
indented code block
![Page 4: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/4.jpg)
Comparison OperatorsEqual toGreater than Less thanGreater than or equal toLess than or equal toNot equal to
==><>=<=!=
![Page 5: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/5.jpg)
Else- SyntaxWhat if you want something to happen when the if condition is false?
![Page 6: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/6.jpg)
If Else - Example
![Page 7: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/7.jpg)
Checking for Multiple Conditions
We use an elif statement to check multiple conditions.
![Page 8: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/8.jpg)
Elif - Example
![Page 9: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/9.jpg)
Logic OperatorsCheck for multiple conditions in the same keyword.There are only three: and, or, not.
![Page 10: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/10.jpg)
Precedence
![Page 11: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/11.jpg)
You asleep yet?
![Page 12: Python – Making Decisions](https://reader036.vdocuments.mx/reader036/viewer/2022062723/56813d12550346895da6cfe1/html5/thumbnails/12.jpg)
Logic Example