1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olga2289 [7]
4 years ago
12

PythonFunction Name: doublesParameters: list of int Returns: list of intDescription: Write a function, doubles, that takes a lis

t 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.Sample Inputs/Outputs:Example Call: doubles([1, 2, 4, 3, 6])Expected Return: [2, 4, 6]Example Call: doubles([3, 0, 1, 2, 3, 6, 2, 4, 5, 6, 5])Expected Return: [2, 6, 4]

Computers and Technology
1 answer:
lawyer [7]4 years ago
4 0

Answer:

def doubles(ls):

   new = []

   for i in ls:

       for a in ls:

           if (i == a*2) and (i not in new) and i != 0:

               new.append(i)

               break

   return new

   

ls = [3, 0, 1, 2, 3, 6, 2, 4, 5, 6, 5]

print(doubles(ls))

Explanation:

The code is written in python.

The function doubles is created and it has one parameter.

In the function, a new list is created to hold the values that are exactly twice the previous integer in the list.

Two nested for loops are used with an if statement to achieve the desired result. The first FOR loop gets a number from the list entered by the user and holds that number while it waits for the second for loop and the if statement. The second FOR loop, iterates through all the elements in the list and compares them with the number being held by the first for loop through the IF statement.

The IF statement checks 3 things:

  • if the first number is x2 the second
  • if it is not already contained in the list
  • if the number is not zero

All these conditions must pass as True before the number is appended to the new list.

The break statement is there to ensure that the loop does not start evaluating unnecessary conditions, so when a match is found for one element the second loop breaks thereby allowing the first FOR loop to move to the next number.

Finally, the new list is returned and the function is called.

I have attached a picture of the result.

You might be interested in
Who<br> invented the term “debugging”?
Black_prince [1.1K]

Grace Murray Hopper invented it

8 0
3 years ago
Read 2 more answers
____ that allow individuals to perform specific tasks are launched via the operating system, such as by using the windows start
schepotkina [342]
Programs that allow individuals to perform specific tasks are launched via the operating system, such as by using the windows start menu on windows computers. Programm is a set of instructions written for a computer.<span>The Start menu contains icons for all installed programs and data collections, usually for programs.</span>
3 0
3 years ago
. What part of the communication feedback loop results in unclear communication? A. Sender's message B. Interference C. Message
MakcuM [25]
D is ur final answer i hope i helped
7 0
3 years ago
Read 2 more answers
Write the definition of a function named averager that receives a double parameter and return-- as a double -- the average value
lys-0071 [83]

Answer:

Following are the definition of function  

double averager (const double &x)  // function definition

{

static double z = 0.0;  // variable declaration

static size_t c = 0;

 c=c+1;  // increment of c by 1

z =z+ x;  // adding value  

return z /c ;   // return average  

}

Explanation:

Following are the description of statement  

  • Create a function averager of double type that holds a parameter "x" of the double type .
  • In this function we declared a variable "z" of a static double type that value is initialized by 0.
  • The static variable is used to retain value.
  • Declared a variable "c" of size_t type that holds a value 0 .
  • After that increment the value of c by 1 .
  • adding the value of "z" variable to the "x" and storing the result into the z variable.
  • Finally return the average value  
4 0
3 years ago
What device makes it possible for multiple customers to share one address
Galina-37 [17]
A=NAT is correct I think
6 0
3 years ago
Other questions:
  • When a hostname is configured through the cisco cli, which three naming conventions are part of the guidelines? (choose three.)?
    15·1 answer
  • What is Mainframe computer​
    14·1 answer
  • A(n) _____ is an organized collection of people, procedures, software, databases, and devices that stores and retrieves knowledg
    6·1 answer
  • ____ assigns a risk rating or score to each information asset. Although this number does not mean anything in absolute terms, it
    8·1 answer
  • At each layer of the OSI model, data is appended to the original message and then sent on to the next lower layer. What is this
    10·1 answer
  • Antwon is building his technical writing portfolio.He created the following checklist: •check whether any part of the portfolio
    11·1 answer
  • 30 points
    7·1 answer
  • Я люблю есть гнезда петух
    11·1 answer
  • Alguien me podria ayudar a hacer este codigo porfavor? en php Desarrolle el código que solicite los datos (desde teclado) Nombre
    10·1 answer
  • How has the Internet expanded the reach of all of these types of media?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!