def calculate_square_sums(list_squares): """ # vladosiks_mosiks solution Владислав = [0] result = [] for Владислав in list_squares: # Continuation (Andrii Khukhrianskii) Path 1 #result.append(Владислав[0] * Владислав[1]) # Unpack (Распаковка) - Сохранения выражений в несколько переменных side_1, side_2 = Владислав result.append(side_1 * side_2) return result """ # Andrii Khukrianskii solution # Генератор списков (List Comprehension) return [sides[0] * sides[1] for sides in list_squares]
- def calculate_square_sums(list_squares):
- """
- # vladosiks_mosiks solution
- Владислав = [0]
- result = []
- for Владислав in list_squares:
- # Continuation (Andrii Khukhrianskii) Path 1
- #result.append(Владислав[0] * Владислав[1])
- # Unpack (Распаковка) - Сохранения выражений в несколько переменных
- side_1, side_2 = Владислав
- result.append(side_1 * side_2)
- return result
- """
- # Andrii Khukrianskii solution
- # Генератор списков (List Comprehension)
- return [sides[0] * sides[1] for sides in list_squares]
Нужно написать функцию, которая будет подсчитывать площади прямоугольников
На вход (пример):
[[5, 8], [4, 10], [15, 40]] -> [40, 40, 600]
Eng
You need to write a function that will count the areas of squares
Example:
[[5, 8], [4, 10], [15, 40]] -> [40, 40, 600]
def calculate_square_sums(list_squares):
pass
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
array = [[5, 8], [4, 10], [15, 40]]
result = calculate_square_sums([[5, 8], [4, 10], [15, 40]])
test.assert_equals(result, [40, 40, 600])
def count_sheeps(sheeps): ''' Vladosiks_mosiks solution print(sum(1 for w in sheeps.split() if w.rstrip(',.!?:;') == 'True')) return 0 ''' # Andrii Khukhrianskii solution (Path 1) # return sheeps.count(True) # Andrii Khukhrianskii solution (Path 2) sheeps.sort() limit = 0 for sheep in sheeps: # [False, False, False.....] if not sheep: limit += 1 else: break return len(sheeps[limit::])
- def count_sheeps(sheeps):
- '''
- Vladosiks_mosiks solution
- print(sum(1 for w in sheeps.split() if w.rstrip(',.!?:;') == 'True'))
- return 0
- '''
- # Andrii Khukhrianskii solution (Path 1)
- # return sheeps.count(True)
- # Andrii Khukhrianskii solution (Path 2)
- sheeps.sort()
- limit = 0
- for sheep in sheeps: # [False, False, False.....]
- if not sheep:
- limit += 1
- else:
- break
- return len(sheeps[limit::])
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): array1 = [True, True, True, False, True, True, True, True , True, False, True, False, True, False, False, True , True, True, True, True , False, False, True, True] result = count_sheeps(array1) test.assert_equals(result, 17)
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- array1 = [True, True, True, False,
- True, True, True, True ,
- True, False, True, False,
- True, False, False, True ,
- True, True, True, True ,
False, False, True, True],- False, False, True, True]
- result = count_sheeps(array1)
test.assert_equals(array1, 17)- test.assert_equals(result, 17)
Consider an array/list of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).
For example,
[True, True, True, False,
True, True, True, True ,
True, False, True, False,
True, False, False, True ,
True, True, True, True ,
False, False, True, True]
The correct answer would be 17.
Hint: Don't forget to check for bad values like null/undefined
def count_sheeps(sheeps):
pass
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
array1 = [True, True, True, False,
True, True, True, True ,
True, False, True, False,
True, False, False, True ,
True, True, True, True ,
False, False, True, True],
result = count_sheeps(array1)
test.assert_equals(array1, 17)