Python345 1113. Parse nice int from char problem You ask a small girl,"How old are you?" She always says, "x years old", where x is a random number between 0 and 9. Write a program that returns the girl's age (0-9) as an integer. Assume the test input string is always a valid string. For example, the test input may be "1 year old" or "5 years old". The first character in the string is always a number. Solution: def get_age(age): def get_int(ag.. 2022. 11. 13. 1112. Sum of Multiples Your Job Find the sum of all multiples of n below m Keep in Mind n and m are natural numbers (positive integers) m is excluded from the multiples Examples sumMul(2, 9) ==> 2 + 4 + 6 + 8 = 20 sumMul(3, 13) ==> 3 + 6 + 9 + 12 = 30 sumMul(4, 123) ==> 4 + 8 + 12 + ... = 1860 sumMul(4, -7) ==> "INVALID" Solution: def invalid_value(func): def wrapper(n, m): return (n 2022. 11. 13. 1111. Grasshopper - Debug sayHello Debugging sayHello function The starship Enterprise has run into some problem when creating a program to greet everyone as they come aboard. It is your job to fix the code and get the program working again! Example output: Hello, Mr. Spock Solution: class SayHello: def __init__(self): self.__hello = "Hello" def say(self, name): return f"{self.__hello}, {name}" say_hello = SayHello().say 2022. 11. 12. 1110. No oddities here Write a small function that returns the values of an array that are not odd. All values in the array will be integers. Return the good values in the order they are given. Solution: class NoOdd: def __init__(self): self.__values: list[int] = [] def run(self, values: list[int]) -> list[int]: self._set_values(values) self._remove_odd() return self._get_values() def _set_values(self, values) -> None.. 2022. 11. 10. 1109. Sentence Smash Sentence Smash Write a function that takes an array of words and smashes them together into a sentence and returns the sentence. You can ignore any need to sanitize words or add punctuation, but you should add spaces between each word. Be careful, there shouldn't be a space at the beginning or the end of the sentence! Example ['hello', 'world', 'this', 'is', 'great'] => 'hello world this is grea.. 2022. 11. 9. 1108. JavaScript Array Filter In Python, there is a built-in filter function that operates similarly to JS's filter. For more information on how to use this function, visit https://docs.python.org/3/library/functions.html#filter The solution would work like the following: get_even_numbers([2,4,5,6]) => [2,4,6] Solution: def get_even_numbers(arr, condition = lambda x: x % 2 == 0): return [i for i in arr if condition(i)] def g.. 2022. 11. 9. 이전 1 ··· 11 12 13 14 15 16 17 ··· 58 다음