Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

Python code challenges

Author: Kriti Shah
by Kriti Shah
Posted: May 31, 2022
These are beginner-level challenges, but you need to know the Python programming language to complete them so learn python. 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.

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.

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.

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.

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".

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.

Know more : https://youtu.be/slSDox6mzIE

About the Author

I am Digital Marketing intern at igmGuru.

Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Comment 
Pictures
Author: Kriti Shah

Kriti Shah

Member since: Jan 11, 2021
Published articles: 19

Related Articles