12 Python Code Challenges for Rookies


Among the best methods to check and follow your expertise with Python is by fixing coding challenges. You may be taught quite a bit from books and on-line programs, however coding isn’t an armchair exercise. You need to write some code to make real progress.

Coding challenges are good for this. Coding challenges are small issues you’ll be able to clear up with code. Simply because they’re small doesn’t imply they received’t put your data to the take a look at. Every bite-size problem will concentrate on expertise that you simply’ll use later engaged on full software program initiatives.

On this article, we’ll offer you 12 newbie Python coding challenges to get you began. Strive one or two a day to maintain your Python expertise sharp. And if you wish to proceed difficult your Python expertise, we’ll present you ways you are able to do that on the finish of the article.

Begin studying Python immediately

Prime 12 newbie Python code challenges

These are beginner-level challenges, however you’ll want to know the Python programming language to finish them. In case your Python expertise are a bit rusty, take a look at Study Python 3 for a course that’s appropriate for newbies.

You may code your options domestically when you have a improvement surroundings already arrange. If not, check out one of many many websites that may permit you to execute Python code within the browser. And in case you get caught, search Google for assist fixing the issue, however don’t do it too quickly. Give it your greatest shot first.

1. Convert radians into levels

Write a operate in Python that accepts one numeric parameter. This parameter would be the measure of an angle in radians. The operate ought to convert the radians into levels after which return that worth.

Whilst you may discover a Python library to do that for you, it’s best to write the operate your self. One trace you get is that you simply’ll want to make use of Pi with a view to clear up this downside. You may import the worth for Pi from Python’s math module.

2. Kind a listing

Create a operate in Python that accepts two parameters. The primary will likely be a listing of numbers. The second parameter will likely be a string that may be one of many following values: asc, desc, and none.

If the second parameter is “asc,” then the operate ought to return a listing with the numbers in ascending order. If it’s “desc,” then the listing ought to be in descending order, and if it’s “none,” it ought to return the unique listing unaltered.

3. Convert a decimal quantity into binary

Write a operate in Python that accepts a decimal quantity and returns the equal binary quantity. To make this easy, the decimal quantity will all the time be lower than 1,024, so the binary quantity returned will all the time be lower than ten digits lengthy.

4. Rely the vowels in a string

Create a operate in Python that accepts a single phrase and returns the variety of vowels in that phrase. On this operate, solely a, e, i, o, and u will likely be counted as vowels — not y.

5. Disguise the bank card quantity

Write a operate in Python that accepts a bank card quantity. It ought to return a string the place all of the characters are hidden with an asterisk besides the final 4. For instance, if the operate will get despatched “4444444444444444”, then it ought to return “4444”.

6. Are the Xs equal to the Os?

Create a Python operate that accepts a string. This operate ought to depend the variety of Xs and the variety of Os within the string. It ought to then return a boolean worth of both True or False.

If the depend of Xs and Os are equal, then the operate ought to return True. If the depend isn’t the identical, it ought to return False. If there aren’t any Xs or Os within the string, it also needs to return True as a result of 0 equals 0. The string can comprise any kind and variety of characters.

7. Create a calculator operate

Write a Python operate that accepts three parameters. The primary parameter is an integer. The second is among the following mathematical operators: +, -, /, or . The third parameter will even be an integer.

The operate ought to carry out a calculation and return the outcomes. For instance, if the operate is handed 6 and 4, it ought to return 24.

8. Give me the low cost

Create a operate in Python that accepts two parameters. The primary ought to be the complete value of an merchandise as an integer. The second ought to be the low cost proportion as an integer.

The operate ought to return the worth of the merchandise after the low cost has been utilized. For instance, if the worth is 100 and the low cost is 20, the operate ought to return 80.

9. Simply the numbers

Write a operate in Python that accepts a listing of any size that incorporates a mixture of non-negative integers and strings. The operate ought to return a listing with solely the integers within the authentic listing in the identical order.

10. Repeat the characters

Create a Python operate that accepts a string. The operate ought to return a string, with every character within the authentic string doubled. For those who ship the operate “now” as a parameter, it ought to return “nnooww,” and in case you ship “123a!”, it ought to return “112233aa!!”.

11. Convert lowercase to uppercase

For this problem, create a Python operate that accepts a string. The operate ought to return a string, with every lowercase character within the authentic string returned as uppercase characters. For those who ship the operate “goodbye” as a parameter, it ought to return “GOODBYE”.

12. Add dots

Write a operate in Python that accepts a string. The operate ought to return a string and add “.” in between every letter. For instance, in case you ship the operate “expertise” as a parameter, it ought to return “s.okay.i.l.l.s”.

Enhancing your Python expertise

For those who like these Python coding challenges and need to strive your hand at fixing extra, join for an account on our web site immediately. We maintain day by day and weekly coding challenges the place you’ll be able to take a look at your expertise. You could find extra particulars on these coding challenges right here.

If you’ll want to brush up in your Python expertise to finish the newbie challenges, take a look at our Study Python 3 course. It’s an important introduction to each the Python programming language and the basics of programming.

If you wish to check out intermediate or superior coding challenges and already know fundamental Python, then programs like Study Knowledge Buildings and Algorithms with Python, Study Recursion with Python, or Study Advanced Knowledge Buildings will train you what you’ll want to know to unravel extra advanced coding challenges.

This weblog was initially printed in August 2021 and has been up to date to incorporate extra Python challenges for newbies.

Whether or not you’re seeking to break into a brand new profession, construct your technical expertise, or simply code for enjoyable, we’re right here to assist each step of the way in which. Try our weblog submit about how to decide on one of the best Codecademy plan for you to find out about our structured programs, skilled certifications, interview prep assets, profession companies, and extra.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *