Hello!
Today's question is this!
Create a function that takes two numbers as arguments (
num
,length
) and returns a list of multiples ofnum
until the list length reacheslength
.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 件のコメント:
コメントを投稿