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
Vinvika [58]
2 years ago
10

Given the lists list1 and list2, not necessarily of the same length, create a new list consisting of alternating elements of lis

t1 and list2 (that is, the first element of list1 followed by the first element of list2 , followed by the second element of list1, followed by the second element of list2, and so on. Once the end of either list is reached, the remaining elements of the longer list is added to the end of the new list. For example, if list1 contained [1, 2, 3] and list2 contained [4, 5, 6, 7, 8], then the new list should contain [1, 4, 2, 5, 3, 6, 7, 8]. Associate the new list with the variable list3.
Computers and Technology
1 answer:
tester [92]2 years ago
5 0

Answer:

The following code is written in Python Programming Language.

Program:

list1=[1,2,3]

 # initialized the list type variable

list2=[4,5,6,7,8]

  # initialized the list type variable

list3=[]

   # initialized the empty list type variable

for j in range(max(len(list1), len(list2))):   #set for loop

 if j<len(list1):

  #set if statement

   list3.append(list1[j])

  #value of list1 appends in list3  

 if j<len(list2):

   #set if statement

   list3.append(list2[j])

  #value of list2 append in list3

print(list3)    #print the list of list3

Output:

[1, 4, 2, 5, 3, 6, 7, 8]

Explanation:

Here, we define three list type variables "list1", "list2", "list3" and we assign value in only first two variables "list1" to [1, 2, 3] and "list2" to [4, 5, 6, 7, 8] and third list is empty.

Then, we set the for loop and pass the condition inside it we pass two if conditions, in first one we compare the list1 from variable "j" inside it the value in list1 will append in list3, and in second one we compare "j" with list two and follow the same process.

After all, we print the list of the variable "list3".

You might be interested in
Suppose we wanted to make change for purchases and wanted to use the least number of coins possible. Here is a greedy algorithm:
love history [14]

Answer:

Explanation:

The following code is a Python function that takes in the amount of change. Then it uses division and the modulo operator to calculate the number of coins that make up the changes, using the greatest coin values first.

import math

def amountOfCoins(change):

   print("Change: " + str(change))

   quarters = math.floor(change / 0.25)

   change = change % 0.25

   dimes = math.floor(change / 0.20)

   change = change % 0.20

   pennies = math.floor(change / 0.01)

   print("Quarters: " + str(quarters) + "\nDimes: " + str(dimes) + "\nPennies: " + str(pennies))

5 0
2 years ago
Are used in the Excel application to create calculations
OlgaM077 [116]

Answer:

I think the answer is formulas

6 0
3 years ago
Read 2 more answers
If the list [8,1,4,2,10,0] is sorted with the selection sort algorithm, what is the list at the 4th step of the algorithm?
Savatey [412]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The selection sort algorithm step started from 0, and continue till the sorting is done.

The correct answer after selection sort algorithm at the 4th step is:D

[0,1,2,4,8,10].

The complete detail of step by step execution is shown in the attached document file.

Download docx
5 0
2 years ago
Insert XXX to output the student's ID. public class Student { private double myGPA; private int myID; public getID) { return myI
Aleonysh [2.5K]

Answer:

Explanation:

The question above is missing many details and are actually various questions in one. I will answer each one seperately below...

A. The piece of code to get the ID in this code snippet that needs to replace XXX would be the following ... System.out.println("Student ID: " + s.getID());

B. A static main() can declare and create objects. Once these objects are created their instance methods can then be called.

C. Integer score1 = 72;

    int score2 = 85;

    Character grade = 'C';

     In the above code snippet, the information stored in score1, score2, and grade are the following... obj reference, 85, obj reference. This is becasue both Integer and Character are classes and the values being passed to their variables are referencing that object class, while score2 is a primitive type of int and is therefore simply a number.

D. The statement that is true is ... Contents of a Double instance can be modified after initialization. Objects can be modified by calling its setter methods after initializing it.

7 0
2 years ago
Raymond has to send a number of large documents to his charterer accountant for filing his taxes. Which email etiquette should R
CaHeK987 [17]

Raymond should compress the files, and then at the very least ask what would be the appropriate time to email the attachment. It is important to practice good etiquette when using email. If you are sending an email that has attachments, always make sure to mention it in the body of the email. Raymond should also ZIP or compress his large attachments before sending them. This will make them easier to send.

4 0
3 years ago
Read 2 more answers
Other questions:
  • The inventory tracking system shows that 12 laptop were on hand before a customer brings two laptops to the register for purchas
    9·1 answer
  • Software that instructs the computer how to run applications and controls the display/keyboard is known as the
    14·1 answer
  • Would anyone know this
    10·2 answers
  • A technician has just installed a video card in a PC. The video card is not working, althoughit was working fine on the test ben
    6·1 answer
  • Can an iphone user see when an android user is typing
    10·2 answers
  • In 3 to 5 sentences, describe whether or not files should be deleted from your computer. Explain you answer.
    14·2 answers
  • Evonka is listening to music from an online music provider (such as Pandora or Jango). She builds a list of music preferences, i
    15·1 answer
  • What will the computer do in response to a line of code reading # name = input("What is your name?")
    7·1 answer
  • Privacy, anonymity, and freedom of expression are all interrelated.
    12·1 answer
  •  A programming paradigm is a method used to program a computer that guides the solving of a problem or performing of a task. Whi
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!