-
Notifications
You must be signed in to change notification settings - Fork 1
/
051_Find Number by Given Number.py
64 lines (40 loc) · 1.39 KB
/
051_Find Number by Given Number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Codewars Coding Challenge
Day 51/366
Level: 8kyu
Find numbers which are divisible by given number
Complete the function which takes two arguments and returns all numbers which are divisible by the given divisor. First argument is an array of numbers and the second is the divisor.
Example(Input1, Input2 --> Output)
[1, 2, 3, 4, 5, 6], 2 --> [2, 4, 6]
def divisible_by(numbers, divisor):
https://www.codewars.com/kata/55edaba99da3a9c84000003b/train/python
"""
# My Solution
def divisible_by(numbers, divisor):
result = []
for i in numbers:
if i % divisor == 0:
result.append(i)
return result
print(divisible_by([1,2,3,4,5,6], 2))
"""
Sample tests
import codewars_test as test
from solution import divisible_by
@test.describe("Fixed Tests")
def fixed_tests():
@test.it('Basic Test Cases')
def basic_test_cases():
test.assert_equals(divisible_by([1,2,3,4,5,6], 2), [2,4,6])
test.assert_equals(divisible_by([1,2,3,4,5,6], 3), [3,6])
test.assert_equals(divisible_by([0,1,2,3,4,5,6], 4), [0,4])
test.assert_equals(divisible_by([0], 4), [0])
test.assert_equals(divisible_by([1,3,5], 2), [])
test.assert_equals(divisible_by([0,1,2,3,4,5,6,7,8,9,10], 1), [0,1,2,3,4,5,6,7,8,9,10])
"""
"""
Solutions From Codewars
=1=
def divisible_by(numbers, divisor):
return [num for num in numbers if num % divisor == 0]
"""