본문 바로가기

나는 이렇게 학습한다/Algorithm & SQL405

1220. The 'if' function Create a function called _if which takes 3 arguments: a boolean value bool and 2 functions (which do not take any parameters): func1 and func2 When bool is truth-ish, func1 should be called, otherwise call the func2. Example: def truthy(): print("True") def falsey(): print("False") _if(True, truthy, falsey) # prints 'True' to the console Solution: def _if(bool, func1, func2): return func1() if b.. 2022. 12. 20.
1219. Return the day Complete the function which returns the weekday according to the input number: 1 returns "Sunday" 2 returns "Monday" 3 returns "Tuesday" 4 returns "Wednesday" 5 returns "Thursday" 6 returns "Friday" 7 returns "Saturday" Otherwise returns "Wrong, please enter a number between 1 and 7" Solution: days = { 1: "Sunday", 2: "Monday", 3: "Tuesday", 4: "Wednesday", 5: "Thursday", 6: "Friday", 7: "Saturd.. 2022. 12. 19.
1218. Remove First and Last Character It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters. Solution: def remove_char(s: str, limit: int = 1): return s[limit:-limit] 2022. 12. 18.
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.