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
zubka84 [21]
3 years ago
7

Write a method doubleUp that doubles the size of a list of integers by doubling-up each element in the list. Assume there's enou

gh space in the array to double the size.
Computers and Technology
1 answer:
Savatey [412]3 years ago
6 0

Answer:

The solution in Python is as follows:

class myClass:

    def doubleUp(self,doubleList):

         doubleList[:0] = doubleList[::2] = doubleList[1::2] = doubleList[:]

       

newlist =  []

n = int(input("Number of elements: "))

for i in range(n):

    num = int(input(": "))

    newlist.append(num)

   

list = myClass()

list.doubleUp(newlist)

print(newlist)

Explanation:

Start by creating a class

The solution in Python is as follows:

class myClass:

Then define the method doubleUp

    def doubleUp(self,doubleList):

The duplicates is done here

         doubleList[:0] = doubleList[::2] = doubleList[1::2] = doubleList[:]

The program main begins here

This defines an empty list        

newlist =  []

This prompts user for number of elements

n = int(input("Number of elements: "))

The following iteration get the elements of the list

<em>for i in range(n):</em>

<em>     num = int(input(": "))</em>

<em>     newlist.append(num)</em>

   

This defines the instance of the class

list = myClass()

This calls the method

list.doubleUp(newlist)

Lastly, this prints the duplicate list

print(newlist)

You might be interested in
In a proper webpage, which tag holds all of a webpages visble HTML
Furkat [3]
If I remember correctly, I believe it's <body></body>
6 0
3 years ago
Read 2 more answers
Which of the following is typically used in a flowchart to indicate a decision?
Vilka [71]
Diamond is typically used in a flowchart or indicate a decision.
6 0
3 years ago
In this exercise, your function will receive 2 parameters, the name of a text file, and a list of strings. The function will wri
diamong [38]

Answer:

# the function is defined

# it takes 2 arguments: filename and list of string

def solution(filename, listOfString):

   # the file is opened in write mode

   # so that we can write to it

   with open(filename, 'w') as file_object:

       # we loop through the entire list of string

       # this looping help us know what to write to the file

       for each_string in listOfString:

           # if the length of the string is less than 4

           # we write 'x' with a new line

           if len(each_string) < 4:

               file_object.write("x\n")

           # else if the length of the string is greater than equals 4

           # we write the fourth character

           # and also add new line

           else:

               file_object.write(each_string[3])

               file_object.write("\n")

Explanation:

The function is written in Python. It takes two argument; filename and list of string.

It opens the file in write mode and then loop through the list of string. During the loop, we know what to write to the file.

In the length of a string is less than 4; we write 'x' else we write the fourth character in the string. The fourth character has an index of 3 because string uses zero index counting like a string. Starting from zero; 0, 1, 2, 3, 4... the fourth character has an index of 3.

5 0
3 years ago
Displays information a bout drivers, network connections, and other program-related details.
slava [35]

Answer:

library

Explanation:

hope you like it

6 0
3 years ago
How would you use SQL to change a table's structure? What general types of changes are possible? Which commands are used to impl
xz_007 [3.2K]

The SQL is used to change a table's structure by:

The use of the SQL ALTER TABLE command.

<h3>How is it done?</h3>

The SQL ALTER TABLE command is known to  be that which is often used to alter the structure of an existing table.

It is known to help one to be able to add or delete columns, make or destroy indexes, alter the kinds of existing columns, rename columns or the table itself.

Note that  It can also be used to alter the comment for any kind of table and type of the table therein.

Learn more about SQL from

brainly.com/question/25694408

#SPJ1

4 0
2 years ago
Other questions:
  • In hunter-gather societies most hunting was done by
    9·2 answers
  • ¿Cuál es el objetivo principal de los servicios?
    7·1 answer
  • . One of the vulnerabilities the Morris worm used was a networking service called finger. The purpose of the finger service is t
    11·1 answer
  • On a network, which protocol is responsible for dividing files into chunks, adding headers containing information for reassembli
    10·1 answer
  • Explain the impacts of computer in education
    6·2 answers
  • A sales transaction was coded with an invalid customer account code (XXX-XX-XXX rather than XXX-XXX-XXX). The error was not dete
    12·1 answer
  • The welcome screen of the program 123D consists of ___
    15·1 answer
  • Compare and contrast two fundamental security design principles in network security. Analyze how these principles and how they i
    15·1 answer
  • Java can be procedural or object-oriented when it comes to programming. What is the difference between procedural and OOP?​
    13·1 answer
  • This computer is used by touching your finger.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!