Looking for exercises to improve in Python? Want to get better at Python but not sure what to do?
The best way to learn coding is through practice!
In this article, I present 19 quick exercises for beginners and more advanced Python enthusiasts.
You’ll discover numerous concepts that will be useful in your daily programming when you create more complex programs.
💡 By the way, if you’re looking for longer projects, then my article 9 Python Project Ideas for Beginners will surely interest you.
Let’s dive right into this list of the best exercises to do to learn Python!
This first exercise serves as a “Hello world!” Display a string of your choice using the
print() function in Python.
Continuing with the
Write a function that adds up each element of a list of numbers and then displays it. Essentially, you’re rewriting the native
Write a script that reads a number with the
input() function and displays its conversion from Fahrenheit to Celsius. To go further, you can propose 2 modes: Celsius to Fahrenheit and Fahrenheit to Celsius. Allow the user to choose a conversion mode with another
Write a script that gives all even numbers between two numbers.
The easiest interpretation of this exercise might be to hardcode a number and then give all even numbers between 0 and that number.
You can go further by using a list or by using the
input function to make your program interactive.
is_prime() function that returns
False depending on whether the number given to the function is a prime number or not.
Create a loop to display all elements of a dictionary. To go further, you can display the key and value of each element of a dictionary independently, formatting them in the way you choose with the
Code a program that displays the Fibonacci sequence up to a number. This number can be hardcoded into your code or requested from the user with the
Create a small program that displays the vowels in a string.
Code a script that takes a list of numbers and displays the odd numbers in that list.
Program a script that displays the total number of characters in a list of words.
To go further, for example, transform your code into a function that takes lists as parameters, check that they are indeed lists containing words and not other types of variables.
Create a program that changes the order of elements in a list by reversing them.
[1, 2, 3, 4] becomes
[4, 3, 2, 1].
Code a program that gives the factorial of a number.
As a reminder, the factorial is the result of the multiplication of all numbers less than or equal to a given number.
For example, for 6 we have 1, 2, 3, 4, 5, and 6. So to get the factorial of 6 (!6) we multiply 1 x 2 x 3 x 4 x 5 x 6 = 720.
The product of !6 is 720.
A palindrome is a word that can be read in both directions, like “Bob” for example.
Write a function that checks if the word is a palindrome or not, returning
You may know the meme of SpongeBob that aims to mock someone by taking their sentence and alternating the letters between uppercase and lowercase?
Well, today you’re going to code your generator to alternate the letters between uppercase and lowercase because that’s exactly what you’re asked to do in this exercise!
Create a program that calculates the average of numbers in a list.
Create a program that displays the largest number in a list.
Create a program that displays the longest string in a list of words.
Create a program that displays the numbers in a list that are divisible by 3.
You now have plenty of exercises to improve in Python.
As I mentioned at the beginning of this article, I wrote an article 9 Python Project Ideas for Beginners for those who want to design longer projects in Python but don’t have too many ideas.
Hey, I'm Thomas 👋 Here, you'll find articles about tech, and what I think about the world. I've been coding for 20+ years, built many projects including Startups. Check my About/Start here page to know more :).