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
____ refers to typing your entire e-mail message or discussion group post using only capital letters.
Over [174]
The answer to this question is: Shouting
7 0
3 years ago
Consider the following 3-PARTITION problem. Given integers a1; : : : ; an, we want to determine whether it is possible to partit
ZanzabumX [31]

Answer:

Explanation:

Find attach the solution

6 0
3 years ago
In the Unified Process (UP), related activities are grouped into UP ____. a. Services b. Disciplines c. Cycles d. Practices
Paha777 [63]

Answer:

b. Disciplines

Explanation:

The Unified Process (UP) is a type of development framework that repeats itself and can be customized and used for several different variations of the same underlying process. In the Unified Process (UP), related activities are grouped into UP Disciplines, as one of the many components that make up the Unified Process.

6 0
3 years ago
A career action plan is used to:
Ede4ka [16]

A career action plan is typically used to: A. organize career-related thoughts and goals.

<h3>What is a career action plan?</h3>

A career action plan can be defined as a planning document which is developed, owned and managed by an individual, so as to help him or her to organize and reflect on his or her increased career development learning.

This ultimately implies that, a career action plan is typically used by an individual to organize career-related thoughts, clear vision and goals.

Read more on career action plan here: brainly.com/question/6947486

#SPJ1

8 0
2 years ago
You are a networking consultant who has been asked to penetration test the network of a small business. you located a target wir
cluponka [151]
<span> In a network that uses WPA2-PSK encryption you can bypass the encryption by using the weakness in the WPA2-PSK system and that is the following:the encrypted password is shared in what is known as the 4-way handshake. </span> When a client authenticates to the access point, the client and the AP go through a 4-step process of authentication.
8 0
4 years ago
Other questions:
  • Kaiden would like to find the list of physical disk drives that are connected to a Linux system. Which directory contains a subd
    14·1 answer
  • I am having trouble with logic gates(AND NOR,etc)
    8·2 answers
  • Tomi is testing all of the links on her web page by clicking on each one in a browser. What type of testing is this considered?
    6·2 answers
  • Describe the certifications developed by SANS. How are they different from InfoSec certifications like CISSP and SSCP?
    11·1 answer
  • When you set the position property for a block element to absolute, the browser?
    8·1 answer
  • Determine the hexadecimal value of a mask that can be used to complement the values of thefirst and third bits of f1ag and leave
    10·1 answer
  • Gear systems with __________ can have both drive and driven gears on the same shaft. a. an odd number of gears b. an even number
    6·1 answer
  • Information systems that support the sales process of B2C companies are typically Web storefronts that customers use to enter an
    11·1 answer
  • OO<br>(A) 3 and 5<br>(B) 4 and 8<br>(C) 2 and 0<br>(D) 6 and 9<br>2. There are twelve books on a shelf and four children in a ro
    12·1 answer
  • 2. BIOS is contained in ROM and not in RAM. Can you guess why?​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!