Given two numbers, you must create a list of N items that alternates between one and the other.
Example:
If the input is "first_number"=2, "second_number"=5, "elements_on_list"=10,"range_begins_at"=0 the output should be:
[2, 5, 2, 5, 2, 5, 2, 5, 2, 5]
If the input is "first_number"=10, "second_number"=7, "elements_on_list"=23,"range_begins_at"=0 the output should be:
[10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10]
def generate_binay_list(first_number,second_number,elements_on_list,range_begins_at):
return [first_number if x%2==0 else second_number for x in range(range_begins_at, elements_on_list)]
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
test_classes=[]
class test_class():
def __init__(self,first_number,second_number,elements_on_list,range_begins_at,expected):
self.first_number=first_number
self.second_number=second_number
self.elements_on_list=elements_on_list
self.range_begins_at=range_begins_at
self.expected=expected
test_classes.append(test_class(2,5,10,0,[2, 5, 2, 5, 2, 5, 2, 5, 2, 5]))
test_classes.append(test_class(10,7,23,0,[10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10, 7, 10]))
test_classes.append(test_class(0,0,0,0,[]))
test_classes.append(test_class(-7,14,-3,0,[]))
test_classes.append(test_class(-7,14,-3,-7,[14, -7, 14, -7]))
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
for obj in test_classes:
result=generate_binay_list(obj.first_number,obj.second_number,obj.elements_on_list,obj.range_begins_at)
test.assert_equals(result,obj.expected)