본문 바로가기

Python345

1217. Regexp Basics - is it a digit? Implement String#digit? (in Java StringUtils.isDigit(String)), which should return true if given object is a digit (0-9), false otherwise. Solution: def is_digit(n): return len(n) == 1 and n.isdigit() 2022. 12. 17.
1216. Define a card suit You get any card as an argument. Your task is to return the suit of this card (in lowercase). Our deck (is preloaded): DECK = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS', '2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AD', '2H','3H','4H','5H','6H','7H','8H','9H','10H','JH','QH','KH','AH', '2C','3C','4C','5C','6C','7C','8C','9C','10C','JC','QC','KC','AC'] ('3.. 2022. 12. 17.
1215. Is it even? In this Kata we are passing a number (n) into a function. Your code will determine if the number passed is even (or not). The function needs to return either a true or false. Numbers may be positive or negative, integers or floats. Floats with decimal part non equal to zero are considered UNeven for this kata. Solution: def is_even(n): return not n % 2 2022. 12. 15.
1214. Find the position! When provided with a letter, return its position in the alphabet. Input :: "a" Ouput :: "Position of alphabet: 1" Solution: def position(alphabet): return f"Position of alphabet: {ord(alphabet)-96}" 2022. 12. 14.
1213. Exclamation marks series #1: Remove an exclamation mark from the end of string Description: Remove an exclamation mark from the end of a string. For a beginner kata, you can assume that the input data is always a string, no need to verify it. Examples remove("Hi!") == "Hi" remove("Hi!!!") == "Hi!!" remove("!Hi") == "!Hi" remove("!Hi!") == "!Hi" remove("Hi! Hi!") == "Hi! Hi" remove("Hi") == "Hi" Solution: def remove(s): if a := s and s[-1] == "!": ... return a and s[:-a] or s 2022. 12. 13.
1212. String cleaning Your boss decided to save money by purchasing some cut-rate optical character recognition software for scanning in the text of old novels to your database. At first it seems to capture words okay, but you quickly notice that it throws in a lot of numbers at random places in the text. Examples (input -> output) '! !' -> '! !' '123456789' -> '' 'This looks5 grea8t!' -> 'This looks great!' Your har.. 2022. 12. 12.