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
NEED HELP
amid [387]

Answer:

i would do B

Explanation:

I YOUNGI

I MIDDLE I

I   AGED  I

I     MEH   I

I_______ I

\ kinda old/

  \ ____ /

   I OLD I

3 0
3 years ago
How to send a message to another channel with an emoji slack
Advocard [28]

Answer: Tap and hold the message you'd like to share and select Share message. Tap the #channel name and choose where you'd like to share the message. Add an optional note, if you'd like. Tap the paper plane icon to share.

Explanation:

7 0
3 years ago
Write a statement to declare and initialize an array of int named denominations that contains exactly six elements. Your declara
lawyer [7]

Answer:

// here is statement in C++ to declare and initialize an array.

int denominations[]={1, 5, 10, 25, 50, 100};

Explanation:

In C++, an array can be declare and initialize in a single statement.Syntax to declare and initialize an array in C++ is type <type> <name>[]={val1,vale2...valn}. Here first literal is type of array and second is name of the array.And in the {} braces value of the array.In the above statement type is integer and name of the array is "denominations" and the values are 1,5,10,25,50,100.

//here is implementation in C++.

// include headers

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// declare and initialize array

int denominations[]={1, 5, 10, 25, 50, 100};

return 0;

}

7 0
4 years ago
You are testing a web application for sql injection vulnerabilities. you send various sql statements which return results on the
tekilochka [14]

This sounds like a brute-force attempt.

8 0
4 years ago
The United States Army retains a history of all equipment acquisition from approval of requirements through funding, authorizing
Mama L [17]

Answer:

A. data mart

Explanation:

Data mart refers to a structure for storing and retrieving data. Often times, the data mart is usually specific to a business line.

The data contained herein is also specific to a particular department and by so doing this facilitate easy isolation, use and development of the data.

The major advantage of creating data marts is for easy accessibility of data.

7 0
3 years ago
Other questions:
  • What type of devices are a keyboard and a mouse?
    7·1 answer
  • What type of stud is placed below a windowsill to support its weight
    12·1 answer
  • You friends parents are worried about going over their budget for the month. Which expense would you suggest is NOT a need?
    10·1 answer
  • The main purpose of a constructor is to initialize the data members at the moment that an object is created. true or false?
    8·1 answer
  • You have observed that it is possible that some of your organization's projects may end up having little or no value after they
    11·1 answer
  • According to Ohm's Law current equals what?
    7·2 answers
  • Access-lists pose a logical problem which often has more than one solution. Can you think of a different set of rules or placeme
    8·1 answer
  • What happens in the winding house of a mine?​
    15·1 answer
  • The value that decides whether something falls into one category or another is called a ____
    13·1 answer
  • Write the necessary preprocessor directive to enable the use of the stream manipulators like setw and setprecision Additional No
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!