본문 바로가기

STR20

0129. Super Duper Easy Make a function that returns the value multiplied by 50 and increased by 6. If the value entered is a string it should return "Error". Solution: problem = lambda x: "Error" if isinstance(x, str) else x * 50 + 6 2023. 1. 29.
1227. CSV representation of array Create a function that returns the CSV representation of a two-dimensional numeric array. Example: input: [[ 0, 1, 2, 3, 4 ], [ 10,11,12,13,14 ], [ 20,21,22,23,24 ], [ 30,31,32,33,34 ]] output: '0,1,2,3,4\n' +'10,11,12,13,14\n' +'20,21,22,23,24\n' +'30,31,32,33,34' Array's length > 2. Solution: def to_csv_text(array): return '\n'.join(','.join(map(str, i)) for i in array) 2022. 12. 27.
1223. validate code with simple regex Basic regex tasks. Write a function that takes in a numeric code of any length. The function should check if the code begins with 1, 2, or 3 and return true if so. Return false otherwise. You can assume the input will always be a number. Solution: def validate_code(code: int) -> bool: return int(str(code)[0]) 2022. 12. 23.
1222. Formatting decimal places #0 Each number should be formatted that it is rounded to two decimal places. You don't need to check whether the input is a valid number because only valid numbers are used in the tests. Example: 5.5589 is rounded 5.56 3.3424 is rounded 3.34 Solution: def two_decimal_places(n: float) -> float: l, r = str(n).split(".") r = str(round(int("1"+r[:5]), -3)) return float(".".join([l, r[1:3]])) def two_de.. 2022. 12. 23.
1025. Exclusive "or" (xor) Logical Operator Exclusive "or" (xor) Logical Operator Overview In some scripting languages like PHP, there exists a logical operator (e.g. &&, ||, and, or, etc.) called the "Exclusive Or" (hence the name of this Kata). The exclusive or evaluates two booleans. It then returns true if exactly one of the two expressions are true, false otherwise. For example: false xor false == false // since both are false true x.. 2022. 10. 26.
1005. Palindrome Strings Palindrome strings A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. This includes capital letters, punctuation, and word dividers. Implement a function that checks if something is a palindrome. If the input is a number, convert it to string first. Examples(Input ==> Output) "anna" ==> true "walter" ==> false 12321 ==> true 123456 =.. 2022. 10. 5.