Posts

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.

Add the Index Python Programming

Image
Problem:- Given a list of numbers, create a function that returns the list but with each element's index in the list added to itself. This means you add 0 to the number at index 0, add 1 to the number at index 1, etc... Examples:- add_indexes([0, 0, 0, 0, 0]) ➞ [0, 1, 2, 3, 4] add_indexes([1, 2, 3, 4, 5]) ➞ [1, 3, 5, 7, 9] add_indexes([5, 4, 3, 2, 1]) ➞ [5, 5, 5, 5, 5] 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.

Characters in Shapes Python Programming

Image
Problem:- Create a function to calculate how many characters in total are needed to make up the shape. You will be given a list of strings that make up a shape in the compiler (i.e. a square, a rectangle, or a line). Examples:- count_characters([   "###",   "###",   "###" ]) ➞ 9 count_characters([   "22222222",   "22222222", ]) ➞ 16 count_characters([   "------------------" ]) ➞ 18 count_characters([]) ➞ 0 count_characters(["", ""]) ➞ 0 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.