Python Basics Exercises: Conditional Logic and Control Flow (Overview)

In Python Basics: Conditional Logic and Control Flow, you learned that much of the Python code you’ll write is unconditional. That is, the code doesn’t make any choices. Every line of code is executed in the order that it’s written or in the order that functions are called, with possible repetitions inside loops.

In this course, you’ll revisit how to use conditional logic to write programs that perform different actions based on different conditions. Paired with functions and loops, conditional logic allows you to write complex programs that can handle many different situations.

In this video course, you’ll use the following:

  • Boolean comparators: ==, !=, <, >, <=, >=
  • Logical operators: and, or, not
  • Conditional logic: ifelifelse
  • Exception handling: tryexcept
  • Loops: for, while
  • Control flow statements: break, continue

Along the way, you’ll also get some insight into how to tackle coding challenges in general, which can be a great way to level up as a developer.

This video course is part of the Python Basics series, which accompanies Python Basics: A Practical Introduction to Python 3. You can also check out the other Python Basics courses.

Note that you’ll be using IDLE to interact with Python throughout this course.

Download

Sample Code (.zip)

3.8 KB
Download

Course Slides (.pdf)

5.3 MB

00:00 Welcome to this Real Python Exercises course, where you’ll practice using conditional logic and control flow.

00:08 Our exercises courses are all about training. You’ll train the process of writing code by solving carefully selected exercises. You’ll also train reading over other people’s code and communicating your thought process. Doing all that, you’ll practice the concepts that you’ve learned about in an associated course or tutorial and help make them stick. In the upcoming lessons, I’ll introduce you to tasks, give you an opportunity to solve them yourself, and then show you step by step how I solved each of them.

00:37 So you’ll go through three steps for each task. You’ll learn about the exercise, you’ll code your own solution, and then you’ll compare your solution and the process that you got there to with mine. When I walk you through a task, I’ll explain what I do and also why I do it like that.

00:54 That’ll give you a chance to compare not just our final solutions, but also how we got there. Maybe you’ll gain some insights on the process of getting from a task description to a working solution in code.

01:05 Or maybe you’ll be plunged into deep despair regarding why it takes me so long to tackle a task that was immediately obvious to you.

01:13 You’ll start with solving some review exercises in the first section, and then slowly, you’ll build up towards a proper challenge. In the second section, you’ll code up a text-based role-playing game.

01:24 This challenge will give you lots of opportunities to use the conditional logic and control flow concepts that you’ve learned about and trained up to this point.

01:32 You’ll also build a fun project at the same time that you can continue to develop more. Before starting this course, you should have watched the Python Basics course on Conditional Logic and Control Flow. If you went through that course, then you’re well equipped to solve the tasks that I’ll throw at you.

01:49 The concepts that you’ll practice are Boolean comparators, logical operators, conditional logic, exception handling, loops, and control flow statements.

02:03 If you’re somewhat familiar with these concepts and you want to fortify your knowledge with practical programming tasks, then this course is exactly right for you. Before you get started, there’s another tiny bit of background for this course, which is that I’ll use IDLE, the Integrated Development and Learning Environment that comes bundled with Python. If you’ve gone through the Python Basics courses, then you’re already familiar with the tool. If not, and you want to know more, then you can check out these associated courses that cover getting started with IDLE.

02:33 But if you’re just here to train, and you’ve transcended the different looks of different code editors, then feel free to use whatever tool you like to solve the upcoming coding tasks.

02:43 And that’s all there is to say to get you set up. If you’re ready to get started and do some hands-on programming, then see you in the next lesson. There, I’ll introduce the first exercise to get you warmed up, and I won’t tell you what to do if you’re not ready, but I think that taking a break is always a good idea.

Become a Member to join the conversation.