10 Python Code Challenges for Beginners
One of the best ways to test and practice your skills with Python is by solving coding challenges. You can learn a lot from books and online courses, but coding isn’t an armchair activity. You have to write some code to make genuine progress.
Coding challenges are perfect for this. Coding challenges are small problems you can solve with code. Just because they’re small doesn’t mean they won’t put your knowledge to the test. Each bite-size challenge will focus on skills that you’ll use later working on complete software projects.
In this article, we’ll give you 10 beginner Python coding challenges to get you started. Try one or two a day to keep your Python skills sharp. And if you want to continue challenging your Python skills, we’ll show you how you can do that at the end of the article.
Top 10 beginner Python code challenges
These are beginner-level challenges, but you need to know the Python programming language to complete them. If your Python skills are a little rusty, check out Learn Python 3 for a course that’s suitable for beginners.
You can code your solutions locally if you have a development environment already set up. If not, try out one of the many sites that will allow you to execute Python code in the browser. And if you get stuck, search Google for help solving the problem, but don’t do it too soon. Give it your best shot first.
1. Convert radians into degrees
Write a function in Python that accepts one numeric parameter. This parameter will be the measure of an angle in radians. The function should convert the radians into degrees and then return that value.
While you might find a Python library to do this for you, you should write the function yourself. One hint you get is that you’ll need to use Pi in order to solve this problem. You can import the value for Pi from Python’s math module.
2. Sort a list
Create a function in Python that accepts two parameters. The first will be a list of numbers. The second parameter will be a string that can be one of the following values: asc, desc, and none.
If the second parameter is “asc,” then the function should return a list with the numbers in ascending order. If it’s “desc,” then the list should be in descending order, and if it’s “none,” it should return the original list unaltered.
3. Convert a decimal number into binary
Write a function in Python that accepts a decimal number and returns the equivalent binary number. To make this simple, the decimal number will always be less than 1,024, so the binary number returned will always be less than ten digits long.
4. Count the vowels in a string
Create a function in Python that accepts a single word and returns the number of vowels in that word. In this function, only a, e, i, o, and u will be counted as vowels — not y.
5. Hide the credit card number
Write a function in Python that accepts a credit card number. It should return a string where all the characters are hidden with an asterisk except the last four. For example, if the function gets sent “4444444444444444”, then it should return “4444”.
6. Are the Xs equal to the Os?
Create a Python function that accepts a string. This function should count the number of Xs and the number of Os in the string. It should then return a boolean value of either True or False.
If the count of Xs and Os are equal, then the function should return True. If the count isn’t the same, it should return False. If there are no Xs or Os in the string, it should also return True because 0 equals 0. The string can contain any type and number of characters.
7. Create a calculator function
Write a Python function that accepts three parameters. The first parameter is an integer. The second is one of the following mathematical operators: +, -, /, or . The third parameter will also be an integer.
The function should perform a calculation and return the results. For example, if the function is passed 6 and 4, it should return 24.
8. Give me the discount
Create a function in Python that accepts two parameters. The first should be the full price of an item as an integer. The second should be the discount percentage as an integer.
The function should return the price of the item after the discount has been applied. For example, if the price is 100 and the discount is 20, the function should return 80.
9. Just the numbers
Write a function in Python that accepts a list of any length that contains a mix of non-negative integers and strings. The function should return a list with only the integers in the original list in the same order.
10. Repeat the characters
Create a Python function that accepts a string. The function should return a string, with each character in the original string doubled. If you send the function “now” as a parameter, it should return “nnooww,” and if you send “123a!”, it should return “112233aa!!”.
Improving your Python skills
If you like these Python coding challenges and want to try your hand at solving more, sign up for an account on our website today. We hold daily and weekly coding challenges where you can test your skills. You can find more details on these coding challenges here.
If you need to brush up on your Python skills to complete the beginner challenges, check out our Learn Python 3 course. It’s a great introduction to both the Python programming language and the fundamentals of programming.
If you want to try out intermediate or advanced coding challenges and already know basic Python, then courses like Learn Data Structures and Algorithms with Python, Learn Recursion with Python, or Learn Complex Data Structures will teach you what you need to know to solve more complex coding challenges.