Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created December 31, 2020 01:22
Show Gist options
  • Save ZechCodes/c4722a9912941e5ee89f9a4ea5870861 to your computer and use it in GitHub Desktop.
Save ZechCodes/c4722a9912941e5ee89f9a4ea5870861 to your computer and use it in GitHub Desktop.
Challenge 155 - List of Multiples

Challenge 155 - List of Multiples

Create a function that takes two numbers as arguments (num & length) and returns a list of multiples of num until the list length reaches length.

Examples

list_of_multiples(7, 5) ➞ [7, 14, 21, 28, 35]

list_of_multiples(12, 10) ➞ [12, 24, 36, 48, 60, 72, 84, 96, 108, 120]

list_of_multiples(17, 6) ➞ [17, 34, 51, 68, 85, 102]

Notes

  • Notice that num is also included in the returned list.
from __future__ import annotations
import unittest
def list_of_multiples(num: int, length: int) -> list[int]:
return [] # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(list_of_multiples(7, 5), [7, 14, 21, 28, 35])
def test_2(self):
self.assertEqual(list_of_multiples(12, 10), [12, 24, 36, 48, 60, 72, 84, 96, 108, 120])
def test_3(self):
self.assertEqual(list_of_multiples(17, 7), [17, 34, 51, 68, 85, 102, 119])
def test_4(self):
self.assertEqual(list_of_multiples(630, 14), [630, 1260, 1890, 2520, 3150, 3780, 4410, 5040, 5670, 6300, 6930, 7560, 8190, 8820])
def test_5(self):
self.assertEqual(list_of_multiples(140, 3), [140, 280, 420])
def test_6(self):
self.assertEqual(list_of_multiples(7, 8), [7, 14, 21, 28, 35, 42, 49, 56])
def test_7(self):
self.assertEqual(list_of_multiples(11, 21), [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220, 231])
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment