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
4 brainly
Allushta [10]
Web designers like create websites for businesses
6 0
2 years ago
im past 1000 pts and it still hasnt up my rank from VIRTUOSO to EXPERT can someone explain and yes i have brainly plus
FromTheMoon [43]

Answer:

GREAT!

Explanation:

give me crown please

6 0
2 years ago
Read 2 more answers
Some of y'all make me lose braincells with your questions
boyakko [2]

Answer:

ok done we will try

BTW have a nice day enjoy your day Stay blessed stay happy stay strong

5 0
2 years ago
Read 2 more answers
Why is art important to heritage?
Sophie [7]
<span>but of culture, values and traditions. Cultura</span>
7 0
3 years ago
I hate school...............
butalik [34]

Answer:

Check your email.

Explanation:

8 0
2 years ago
Read 2 more answers
Other questions:
  • Machine language library routines are installed on computers Select one: a. because they can come as part of the operating syste
    15·1 answer
  • What is a critique of the feature detector model of object recognition?​?
    8·1 answer
  • How do social media sites illustrate kindness?
    15·1 answer
  • Which option helps you choose the design of a slide in a presentation?
    10·1 answer
  • Which represents the hierarchical structure of a Google Analytics account from top to bottom?
    5·1 answer
  • the easiest and cheapest time to alter the information system is in the ________ phase of the sdlc. a. requirements analysis b.
    8·1 answer
  • A wireless network does not benefit like a wired network does, when it comes to collision reduction. Which device reduces collis
    6·1 answer
  • The merge sort algorithm____________.A. Can be used only on vectors of even length.B. Works by reducing vectors down to the base
    9·1 answer
  • How can I download music and films at home without breaking the law?
    11·2 answers
  • When conducting memory and recall tests, some people make an effort to normalize memories by not reporting extreme cases. this l
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!