Python Basics Exercises: Functions and Loops (Summary)
In this video course, you practiced what you learned in Python Basics: Functions and Loops. You created custom functions, which consist of two parts:
- The function signature, initiated with the
def
keyword, which includes the function’s name and parameters. - The function body, where the code executes every time the function is called.
Functions provide reusable components in your code, preventing repetition and enhancing readability and maintenance.
Along the way, you practiced using for
loops, taking input from the user, and formatting numbers in f-strings.
If you haven’t already tackled the Python Basics: Functions and Loops Quiz, now is a great time to give it a whirl.
For further insights into the concepts covered in this video course, you can refer to the following tutorials:
- Defining Your Own Python Function
- The Python
return
Statement: Usage and Best Practices - Python
for
Loops (Definite Iteration)
Or you can explore the following video courses:
- Defining and Calling Python Functions
- Using the Python
return
Statement Effectively for
Loops in Python (Definite Iteration)
To continue your Python learning journey, check out the other Python Basics courses. You might also consider 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
Congratulations, you’ve made it to the last lesson of this Python Basics Exercises video course, and in this course, you practiced using functions, user input, basic arithmetic, and for
loops to solve the exercises and the challenges.
00:17 You used code comments to help you get organized. You broke up the exercises into smaller tasks. You used descriptive variable names, which is always a good idea, and you repeatedly tested to see whether the code does what you expect it to do.
00:33 If you want to deepen your knowledge about functions and loops even more, I have some additional resources for you.
00:40 In Defining Your Own Python Functions, you learn how to define and call your own Python function. You also learn about passing data to your function and returning data from your function back to its calling environment.
00:53
And to learn more about the return
statement, we have Usage and Best Practices. This is a step-by-step tutorial where you learn how to use the Python return
statement when writing functions.
01:04
Additionally, you’ll cover some good programming practices related to the use of return
. With this knowledge, you’ll be able to write readable, robust, and maintainable functions in Python.
01:14
Same goes for the tutorial Python for
Loops: Definite Iteration. In this introductory tutorial, you’ll learn about how to perform definite iteration with Python’s for
loops.
01:26
You’ll see how other programming languages implement definite iteration and learn about iterables and iterators, and then tie it all together to learn about Python’s for
loop.
01:37 That’s the perfect addition to this course. If there were some parts where you were unsure how to solve it, then it’s a good idea to revisit these resources.
01:49 I don’t know about you, but I think this course was a good investment. Thanks again for joining me, and until next time, at realpython.com.
rwelk on March 8, 2024
I to spent a lot of time on the investment challange. It forced me to review functions in the suggested resources courses. I added this line so I could use the integer 5 instead which seems to work would this be considered Pythonic?
rate = float(input(“Enter rate of interest: “))/100
John Akpan on July 7, 2024
This is good. To make things simpler, I will use the try and except ValueError in the code. It helps manages the exception codes and troubleshooting.
Become a Member to join the conversation.
Anonymous on Feb. 13, 2024
Spent a little bit too much on this, but learned a lot. Also gave myself some extra challenge by calculating the monthly interest and some small error handling. There are probably minor errors here and there: