Loading video player…

Python Basics Exercises: Functions and Loops (Overview)

As you learned in Python Basics: Functions and Loops, functions serve as the fundamental building blocks in almost every Python program. They’re where the real action happens!

You now know that functions are crucial for breaking down code into smaller, manageable chunks. They enable you to define actions that your program can execute repeatedly throughout your code. Instead of duplicating the same code whenever your program needs to accomplish a particular task, you can simply call the function.

However, there are instances when you need to repeat certain code multiple times in a row. This is where loops become invaluable.

In this Python Basics Exercises video course, you’ll practice:

  • Creating user-defined functions
  • Implementing for loops
  • Getting user input
  • Rounding numbers

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.


Sample Code (.zip)

3.9 KB

Course Slides (.pdf)

7.7 MB

00:00 Hi, I’m Philipp with Real Python, and thanks for joining me today on this very special Python Basics Exercises course where you’ll practice working with functions and loops.

00:12 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.

00:26 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:44 You’ll go through three steps for each task: learn about the exercise, code your own solution, and then you’ll compare your solution with mine. When I walk you through a task, I’ll explain what I do and also why I do it like that.

00:59 That will give you a chance to compare not just our final solution, but also how we got there.

01:06 You’ll start with solving some review exercises in the first section, and then you build up towards a proper challenge. Then you’ll do more review exercises and another challenge, a little bit like you are trapped in a loop, but luckily this loop isn’t infinite.

01:23 And after you solve the challenge, I’ll send you off with some additional resources. But before we move on, let’s have a quick look back.

01:32 Before starting this course, you should have watched the Python Basics course on functions and loops. If you went through that course, you are well equipped to solve the task that I’ll throw at you.

01:44 The concepts that you practice in this course are defining a function, asking for user input, doing basic arithmetic, running for loops, and if you’re somewhat familiar with these concepts and you want to strengthen your knowledge with some practical programming tasks, then this course is exactly right for you.

02:04 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.

02:14 If you’ve gone through the Python Basics courses, then you are already familiar with the tool. If not, then you can check out these associated courses that cover getting started with IDLE.

02:25 If you are just here to train and you’re familiar with other code editors, then feel free to use whatever tool you like to solve the upcoming coding tasks.

02:35 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. And there I’ll introduce you to the first exercise to get you warmed up.

Become a Member to join the conversation.