본문 바로가기

Python345

0922. Love vs friendship If a = 1, b = 2, c = 3 ... z = 26 Then l + o + v + e = 54 and f + r + i + e + n + d + s + h + i + p = 108 So friendship is twice stronger than love :-) The input will always be in lowercase and never be empty. Solution: def words_to_marks(s: str, ord_num: int = 96): return sum(ord(i)-ord_num for i in s) 2022. 9. 22.
0921. Sum without highest and lowest number Task Sum all the numbers of a given array ( cq. list ), except the highest and the lowest element ( by value, not by index! ). The highest or lowest element respectively is a single element at each edge, even if there are more than one with the same value. Mind the input validation. Example { 6, 2, 1, 8, 10 } => 16 { 1, 1, 11, 2, 3 } => 6 Input validation If an empty value ( null, None, Nothing .. 2022. 9. 21.
0920. Difference of Volumes of Cuboids In this simple exercise, you will create a program that will take two lists of integers, a and b. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids a and b. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ([2, 2, 3], [5, 4, 1]), the volume of a is 12 and the volume of b is 20.. 2022. 9. 20.
0919. Cat years, Dog years Kata Task I have a cat and a dog. I got them at the same time as kitten/puppy. That was humanYears years ago. Return their respective ages now as [humanYears,catYears,dogYears] NOTES: humanYears >= 1 humanYears are whole numbers only Cat Years 15 cat years for first year +9 cat years for second year +4 cat years for each year after that Dog Years 15 dog years for first year +9 dog years for seco.. 2022. 9. 19.
0918. Grasshopper - Array Mean Find Mean Find the mean (average) of a list of numbers in an array. Information To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list. For an example list of 1, 3, 5, 7 Add all of the numbers 1+3+5+7 = 16 Divide by the number of values in the list. In this example there are 4 numbers in the list. 16/4 = 4 The mean (or averag.. 2022. 9. 19.
0917. Largest pair sum in array Given a sequence of numbers, find the largest pair sum in the sequence. For example [10, 14, 2, 23, 19] --> 42 (= 23 + 19) [99, 2, 2, 23, 19] --> 122 (= 99 + 23) Input sequence contains minimum two elements and every element is an integer. Solution: def largest_pair_sum(numbers): return sum(sorted(numbers)[-2:]) 2022. 9. 17.