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
amm1812
3 years ago
9

How to interchange first half of the array with second half of array in python?

Computers and Technology
1 answer:
damaskus [11]3 years ago
8 0

Answer:

Following are the code to this question:

l= []#defining an empty list

n=int(input("Enter total element you want to insert: "))#defining variable to input total element

for i in range(0,n):# defining loop to input value in list

   insert=int(input())#defining variable insert to input value

   l.append(insert) # adding the elemenents into the list

x=n//2#calculating midpoint  

l1 =l[:x]#using slicing to hold first-half value in l1 list

l2 =l[x:]#using slicing to hold second-half value in l2 list

print("Before interchange: ")#print message

print ("list : ",l)#print input list

l3=l2 + l1#add value in l3

print("After interchange: ")#print message

#print(l3)  #print list l3

print (str(l3)[1:-1])#print list l3

Output:

please find the attachment.

Explanation:

Description of the code:

  • In the above python program, an empty list l is declared, in the next line, variable n is defined, that input the total number of the list elements. In the next line, the for loop is declared, which uses the insert variable input value and used the append method to add value in the list.
  • In the next step, the variable x is declared, which finds the midpoint of the list, and defines the l1 and l2 lists, that use slicing to hold the first and second half values.
  • In the last step, the l3 list is declared, that adds the l1 and l2 lists and use the print method to print its values.

You might be interested in
If you wanted to look up an article from the Chicago Tribune the best place to start would be
anyanavicka [17]
Books,well trusted websites , news.reports , schools library (online and off ) hope this helps.:-)
7 0
2 years ago
How to scan a screenshot on Brainly?
yulyashka [42]

Answer:

You go to the option that says "snap to solve" an that's it

5 0
2 years ago
Read 2 more answers
Shaniya has misspelled a scientific name in her biology report. She needs to correct it, but she has no access to a computer. Sh
Sav [38]

Answer:

Selection of answers:

Yes, she can navigate the window and do simple editing.

Yes, she can use this application for free and navigate the window.

No, her document is “Read-Only,” so she cannot navigate the window.

No, her application has limited features and she cannot access the document.

Answer is: No, her document is “Read-Only,” so she cannot navigate the window.

3 0
3 years ago
A developer wants to take existing code written by another person and add some features specific to their needs. Which of the fo
anzhelika [568]

Answer:

open-source

Explanation:

open-souce software allows any user to submit modifications of the source code

7 0
2 years ago
. Consider the problem of finding the largest element in a list of n elements. What will be the basic operation of an algorithm
natali 33 [55]

Answer:

Comparison.

Explanation:

When we have to find a largest in a list of n elements.First we have to iterate over the list so we can access all the elements of the list in one go.Then to find the largest element in the list we have to initialize a variable outside the loop with the minimum value possible and in the loop compare each element with this value,if the element is greater than the variable assign the element to the variable.Then the loop will find the largest element and it will be the variable.

4 0
3 years ago
Other questions:
  • Direct connections provide continuous access to the Internet. Many bandwidth options are associated with direct connections. Whi
    9·1 answer
  • Explain the saying "Dress for the position you want, not the position you have."
    6·2 answers
  • What area on the Microsoft® Publisher® application screen shows the name of the publication?
    9·1 answer
  • Assume you are using the MINUS operator to combine the results from two tables with identical structure, CUSTOMER and CUSTOMER_2
    8·1 answer
  • Sales representatives want to capture custom feedback record details related to each Account. The sales reps want to accomplish
    12·1 answer
  • Assume we are testing a variable is_sunny in a while loop. is_sunny = “n”.
    13·1 answer
  • Write a program asks the user for an integer N and then adds up the first N odd integers. For example, if the user asks the sum
    11·1 answer
  • How to convert meters to centimeters in c programming​
    8·1 answer
  • How to transfer bookmarks to new computer
    15·1 answer
  • In terms of computer hardware, where does the actual work of computing take place?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!