12/13/2020

Python Explanation (Edabit // List of multiples)

 Hello!

Today's question is this!

Create a function that takes two numbers as arguments (numlength) 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]

This is my solved code!

def list_of_multiples(num, length):
lst = []
for i in range(length):
lst.append(num + i * num)
return lst

First, make an empty list.

Second, We loop of the length.

Next we will append multiple number.

Lastly, we will return the list.

Easy!


Bye!!!

0 件のコメント:

Super Leo 4!

  Leo : Let's do this! Reimu : I'll kill those monsters, so you go! Leo : Yeah! I'll go to the goal!  Leo : Let's go〜! ? Wai...