Python Basics: Conditional Logic and Control Flow (Summary)
In this course, you learned about conditional statements and conditional logic. You saw how to compare values using comparison operators like <
, >
, <=
, >=
, !=
, and ==
. You also saw how to build complex conditional statements using and
, or
, and not
.
Next, you saw how to control the flow of your program using if
statements. You learned how to create branches in your program using if
… else
and if
… elif
… else
. You also learned how to control precisely how code is executed inside an if
block using break
and continue
.
You learned about the try
… except
pattern to handle errors that may occur during runtime. This is an important construct that allows your programs to handle the unexpected gracefully and keep users happy that the program didn’t crash.
Finally, you applied the techniques that you learned in this course and used the random
module to build some coin toss simulations.
To reinforce what you’ve learned here, complete the quiz in the next lesson. Then, head over to Python Basics Exercises: Conditional Logic and Control Flow.
For more information on the concepts covered in this course, check out the following tutorials:
- Conditional Statements in Python
- Using the “and” Boolean Operator in Python
- Using the “or” Boolean Operator in Python
- Using the “not” Boolean Operator in Python
- Python “for” Loops (Definite Iteration)
- Python “while” Loops (Indefinite Iteration)
- Python Exceptions: An Introduction
- What’s the Zen of Python?
Or you can explore the following video courses:
- Conditional Statements in Python (if/elif/else)
- Using the Python and Operator
- Using the Python or Operator
- Using the Python not Operator
- For Loops in Python (Definite Iteration)
- Mastering While Loops
- Raising and Handling Python Exceptions
Then, keep growing your skill set as a programmer by continuing with the other Python Basics courses and getting yourself a copy of Python Basics: A Practical Introduction to Python 3.
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00
You’ve made it to the end of the course. Well done. In this course, you’ve been comparing lots of values, with numbers and strings and saying if they’re greater than or less than. You’ve used logical operators to combine these comparisons, like and
or or
or to invert them with not
.
00:18
You’ve learned about how to control the flow of your programs by creating branches with if
blocks by using loop keywords, like break
, and how to combine all this with conditional statements and loops to gain massive control over how your program behaves. And finally, you’ve also learned about errors and exceptions and how to handle them with a try
… catch pattern.
00:43 Make sure you practice these constructs a bunch and get them to become second nature. Since these constructs are used all the time when you’re coding, almost all coding languages have nearly identical structures to control the flow of your program. So by learning these well, you are well on your way to becoming a programmer.
01:05
If you’re looking for some additional resources about the topics covered in this course, take a look at the if
, else
, elif
Conditional Statements in Python tutorial, which has an article and a video course.
01:20
You can also check out the article and video courses for the and
, or
, and not
Boolean operators if you want a really deep dive into all the possibilities with them.
01:33
You can also check out the dedicated articles and video courses on for
loops, on while
loops, and exceptions.
Ian RP Team on Jan. 12, 2023
Thanks for letting us know about this oversight! We’ve updated the slides.
Become a Member to join the conversation.
bwhitehd on Jan. 11, 2023
There is nothing in the course slides but a single page with a picture. This should be updated.