183k views
2 votes
Function Name: doubles Parameters: list of int Returns: list of int Description: Write a function, doubles, that takes a list of integers and finds values in the list that are exactly twice the previous integer in the list. Return a list of integers from the parameter that meet the criteria specified.

User Xin Yin
by
5.8k points

1 Answer

2 votes

Answer:

def doubles(numbers):

double_numbers = []

for i in range(len(numbers)-1):

if numbers[i+1] == numbers[i] * 2:

double_numbers.append(numbers[i+1])

return double_numbers

Step-by-step explanation:

*The code is in Python.

Create a function called doubles that takes one parameter, numbers

Initialize an empty list, double_numbers, to hold the double values in the numbers that are exactly twice the previous integer

Create a for loop that iterates through the numbers

If the value of the integer is exactly twice the previous integer, add the integer to the double_numbers using append function

When the loop is done, return the double_numbers

User Kstev
by
6.3k points