Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create a list of multiples of a number

Problem:

List of Multiples
Create a Python 3 function that takes two numbers (value, length) as arguments and returns a list of multiples of value until the size of the list reaches length.

Examples
list_of_multiples(value=7, length=5)[7, 14, 21, 28, 35]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

list_of_multiples(value=17, length=6)[17, 34, 51, 68, 85, 102]

def multiples (value,length):
    """
    Value is number to be multiply
    length is maximum number of iteration up to
    which multiple required.
    """
    for i in range(length):
        out=i
    return i

>Solution :

Pythonic way:

def multiples(value, length):
    return [value * i for i in range(1, length + 1)]


print(multiples(7, 5))
# [7, 14, 21, 28, 35]
print(multiples(12, 10))
# [12, 24, 36, 48, 60, 72, 84, 96, 108, 120]
print(multiples(17, 6))
# [17, 34, 51, 68, 85, 102]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading