본문 바로가기

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

0206. Find the nth Digit of a Number Complete the function that takes two numbers as input, num and nth and return the nth digit of num (counting from right to left). Note If num is negative, ignore its sign and treat it as a positive value If nth is not positive, return -1 Keep in mind that 42 = 00042. This means that findDigit(42, 5) would return 0 Examples(num, nth --> output) 5673, 4 --> 5 129, 2 --> 2 -2825, 3 --> 8 -456, 4 --.. 2023. 2. 7.
0205. pick a set of first elements Write a function to get the first element(s) of a sequence. Passing a parameter n (default=1) will return the first n element(s) of the sequence. If n == 0 return an empty sequence [] Examples arr = ['a', 'b', 'c', 'd', 'e'] first(arr) # --> ['a'] first(arr, 2) # --> ['a', 'b'] first(arr, 3) # --> ['a', 'b', 'c'] first(arr, 0) # --> [] Solution: def first(seq: list[str], n:int = 1) -> list[str]:.. 2023. 2. 5.
0204. Filter the number Filter the number Oh, no! The number has been mixed up with the text. Your goal is to retrieve the number from the text, can you return the number back to its original state? Task Your task is to return a number from a string. Details You will be given a string of numbers and letters mixed up, you have to return all the numbers in that string in the order they occur. Solution: def filter_string(.. 2023. 2. 4.
0203. Parse float Write function parse_float which takes a string/list and returns a number or 'none' if conversion is not possible. Solution: def parse_float(string: str) -> float | None: try: return float(string) except (ValueError, TypeError): return None 2023. 2. 3.
0202. Beginner Series #1 School Paperwork Your classmates asked you to copy some paperwork for them. You know that there are 'n' classmates and the paperwork has 'm' pages. Your task is to calculate how many blank pages do you need. If n < 0 or m < 0 return 0. Example: n= 5, m=5: 25 n=-5, m=5: 0 Waiting for translations and Feedback! Thanks! Solution: def only_int(func): def wrapper(n, m): if n < 0 or m < 0: return 0 return func(n, m) r.. 2023. 2. 2.
0201. Who ate the cookie? For this problem you must create a program that says who ate the last cookie. If the input is a string then "Zach" ate the cookie. If the input is a float or an int then "Monica" ate the cookie. If the input is anything else "the dog" ate the cookie. The way to return the statement is: "Who ate the last cookie? It was (name)!" Ex: Input = "hi" --> Output = "Who ate the last cookie? It was Zach! .. 2023. 2. 1.