Posts

Showing posts with the label Python

Date Format in python programming

Image
Problem:- Create a function that converts a date formatted as MM/DD/YYYY to YYYYDDMM. Examples:- format_date("11/12/2019") ➞ "20191211" format_date("12/31/2019") ➞ "20193112" format_date("01/15/2019") ➞ "20191501" Code:- Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Alphabet Soup Python Programming

Image
Problem:- Create a function that takes a string and returns a string with its letters in alphabetical order. Examples:- alphabet_soup("hello") ➞ "ehllo" alphabet_soup("edabit") ➞ "abdeit" alphabet_soup("hacker") ➞ "acehkr" alphabet_soup("geek") ➞ "eegk" alphabet_soup("javascript") ➞ "aacijprstv" Notes:- You can assume numbers and punctuation symbols won't be included in test cases. You'll only have to deal with a single word, alphabetic characters. Code:- (You can write direct one line code like : return "".join(sorted(txt)) Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Clone a List Python Programming

Image
Problem:- The Code tab has code that attempts to add a clone of a list to itself. There is no error message, but the results are not as intended. Can you fix the code? Examples:- clone([1, 1]) ➞ [1, 1, [1, 1]] clone([1, 2, 3]) ➞ [1, 2, 3, [1, 2, 3]] clone(["x", "y"]) ➞ ["x", "y", ["x", "y"]] Code:- Problem code. Answer code. Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Moving to the End Python Programming

Image
Problem:- Write a function that moves all elements of one type to the end of the list. Examples:- move_to_end([1, 3, 2, 4, 4, 1], 1) ➞ [3, 2, 4, 4, 1, 1] # Move all the 1s to the end of the array. move_to_end([7, 8, 9, 1, 2, 3, 4], 9) ➞ [7, 8, 1, 2, 3, 4, 9] move_to_end(["a", "a", "a", "b"], "a") ➞ ["b", "a", "a", "a"]   Code:-  Note:-  Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Hiding the Card Number Python Programming

Image
Problem:- Write a function that takes a credit card number and only displays the last four characters. The rest of the card numbers must be replaced by ************. Example:- card_hide("1234123456785678") ➞ "************5678" card_hide("8754456321113213") ➞ "************3213" card_hide("35123413355523") ➞ "**********5523" code:- Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Probabilities Part 1 Python Programming

Image
Problem:- Given a list of numbers and a value n, write a function that returns the probability of choosing a number greater than or equal to n from the list. The probability should be expressed as a percentage, rounded to one decimal place. Example:- probability([5, 1, 8, 9], 6) ➞ 50.0 probability([7, 4, 17, 14, 12, 3], 16) ➞ 16.7 probability([4, 6, 2, 9, 15, 18, 8, 2, 10, 8], 6) ➞ 70.0 Notes:- Precent probability of event = 100 * (num of favourable outcomes) / (total num of possible outcomes) The numbers in the list are uniformly distributed and have an equal chance of being chosen. Code:- Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Return the Index of All Capital Letters Python Programming

Image
Problem: -  Create a function that takes a single string as an argument and returns an ordered list containing the indices of all capital letters in the string. Example:- index_of_caps("eDaBiT") ➞ [1, 3, 5] index_of_caps("eQuINoX") ➞ [1, 3, 4, 6] index_of_caps("determine") ➞ [] index_of_caps("STRIKE") ➞ [0, 1, 2, 3, 4, 5] index_of_caps("sUn") ➞ [1] Notes :- Return an empty list if no uppercase letters are found in the string. Special characters ($#@%) and numbers will be included in some test cases. Assume all words do not have duplicate letters. Code:- Note:-  Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Folding a Piece of Paper Python Programming

Image
Problem: -  Create a function that returns the thickness (in meters) of a piece of paper after folding it n number of times. The paper starts off with a thickness of 0.5mm. Example:- num_layers(1) ➞ "0.001m" # Paper folded once is 1mm (equal to 0.001m) num_layers(4) ➞ "0.008m" # Paper folded 4 times is 8mm (equal to 0.008m) num_layers(21) ➞ "1048.576m" # Paper folded 21 times is 1048576mm (equal to 1048.576m) Code:- Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Xs and Os Nobody Knows Edabit Python Programming

Image
Problem:-  Create a function that takes a string, checks, if it has the same number of "x"s and "o"s, and returns either True or False. Return a boolean value (True or False). Return True if the number of x's and o's are the same. Return False if they aren't the same amount. The string can contain any character. When "x" and "o" are not in the string, return True. Code :- Simple Solustion:-         2. Using dictionary comprehension:- Note:-  Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Return the Sum of Two Numbers Python Programming

Image
Problem:- Create a function that takes two numbers as arguments and returns their sum. Example :-                           addition(3, 2) --> 5                          addition(-3, -6) --> -9                          addition(7, 3) --> 10 Code:-                          Note:- Never miss indentation. If you are stuck check the python documentation.

Boolean to String Conversion Python Pogramming Problem

Image
Problem:- Create a function that takes a boolean variable flag and returns it as a string. Examples:- boot_to_string(True) -- > "True" boot_to_string(True) -- > "False" Code:-                          Note:- Don't forget indentation.