range34 0907. Count by X Create a function with two arguments that will return an array of the first n multiples of x. Assume both the given number and the number of times to count will be positive numbers greater than 0. Return the results as an array or list ( depending on language ). Examples count_by(1,10) #should return [1,2,3,4,5,6,7,8,9,10] count_by(2,5) #should return [2,4,6,8,10] Solution: def get_range_index(f.. 2022. 9. 7. If you can't sleep, just count sheep!! If you can't sleep, just count sheep!! Task: Given a non-negative integer, 3 for example, return a string with a murmur: "1 sheep...2 sheep...3 sheep...". Input will always be valid, i.e. no negative integers. Solution: def count_sheep(n): return ''.join(f"{i} sheep..." for i in range(1, n+1)) 2022. 8. 17. Give me a Diamond Jamie is a programmer, and James' girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn't know how to make this happen, he needs your help. Task You need to return a string that looks like a diamond shape when printed on the screen, using asterisk (*) characters. Trailing spaces should be removed, and every line must be terminated with a newline character (\n)... 2022. 8. 14. Consecutive strings You are given an array(list) strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array. Examples: strarr = ["tree", "foling", "trashy", "blue", "abcdef", "uvwxyz"], k = 2 Concatenate the consecutive strings of strarr by 2, we get: treefoling (length 10) concatenation of strarr[0] and strarr[1] folingtrashy (" 12) co.. 2022. 8. 13. Maximum subarray sum The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers: max_sequence([-2, 1, -3, 4, -1, 2, 1, -5, 4]) # should be 6: [4, -1, 2, 1] Easy case is when the list is made up of only positive numbers and the maximum sum is the sum of the whole array. If the list is made up of only negative numbers, return 0 instead. Empty list i.. 2022. 8. 12. Sum of a sequence Your task is to make function, which returns the sum of a sequence of integers. The sequence is defined by 3 non-negative values: begin, end, step (inclusive). If begin value is greater than the end, function should returns 0 Examples 2,2,2 --> 2 2,6,2 --> 12 (2 + 4 + 6) 1,5,1 --> 15 (1 + 2 + 3 + 4 + 5) 1,5,3 --> 5 (1 + 4) Solotion: def sequence_sum(begin_number, end_number, step): return sum(ra.. 2022. 8. 10. 이전 1 2 3 4 5 6 다음