본문 바로가기

나는 이렇게 학습한다575

1003. Find the Remainder Task: Write a function that accepts two integers and returns the remainder of dividing the larger value by the smaller value. Division by zero should return an empty value. Examples: n = 17 m = 5 result = 2 (remainder of `17 / 5`) n = 13 m = 72 result = 7 (remainder of `72 / 13`) n = 0 m = -1 result = 0 (remainder of `0 / -1`) n = 0 m = 1 result - division by zero (refer to the specifications on.. 2022. 10. 3.
1002. Twice as old Your function takes two arguments: current father's age (years) current age of his son (years) Сalculate how many years ago the father was twice as old as his son (or in how many years he will be twice as old). The answer is always greater or equal to 0, no matter if it was in the past or it is in the future. Solution: def twice_as_old(dad_years_old, son_years_old): return abs(dad_years_old - so.. 2022. 10. 3.
1001. Hello, Name or World! Define a method hello that returns "Hello, Name!" to a given name, or says Hello, World! if name is not given (or passed as an empty String). Assuming that name is a String and it checks for user typos to return a name with a first capital letter (Xxxx). Examples: * With `name` = "john" => return "Hello, John!" * With `name` = "aliCE" => return "Hello, Alice!" * With `name` not given or `name` =.. 2022. 10. 2.
0930. Count of positives, sum of negatives Given an array of integers. Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. 0 is neither positive nor negative. If the input is an empty array or is null, return an empty array. Example For input [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15], you should return [10, -65]. Solution: def sorted_arr(func): def w.. 2022. 9. 30.
0929. Summing a number's digits Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits. For example: (Input --> Output) 10 --> 1 99 --> 18 -32 --> 5 Let's assume that all numbers in the input will be integer values. Solution: def get_str_number(func): def wrapper(number): return func(str(number).replace("-", "")) return wrapper @get_str_nu.. 2022. 9. 29.
0928. Grasshopper - Terminal game combat function Create a combat function that takes the player's current health and the amount of damage recieved, and returns the player's new health. Health can't be less than 0. Solution: def combat(health, damage): return max(health-damage, 0) 2022. 9. 28.