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
What are the five types of alignment in word?
valentinak56 [21]
I know of four,
Left-aligned
Center-aligned
right-aligned
justified

5 0
4 years ago
Read 2 more answers
You can initialize more than one variable in a for loop by placing a(n) ____ between the separate statements.
Allushta [10]

Answer:

comma

Explanation:

The for loop is used to execute the specific statement again and again until the condition is false.

The syntax:

for(initialization;condition;increment/decrement)

{

  statement;

}

In the initialization, we an initialize more than one variable by using the 'comma' as separator.

similarly for condition and increment/decrement part as well.

for example:

for(int x = 0,y = 0;x<5,y<5;x++,y++)

{

  statement;

}

we can used as many as possible by using comma

7 0
3 years ago
Read 2 more answers
What are the answers to 14 and 15
RoseWind [281]
The answer to 14 is c and the answer to 16 is a
6 0
3 years ago
CodeHS 3.4.5. What is the code for four colored triangles.
Delicious77 [7]

Answer:

I thinks its CodeHS 3.4.5.

Explanation:

5 0
4 years ago
Jarvis wants to buy a basic scanner for daily use. Which scanner will be suitable for him?
Romashka-Z-Leto [24]

Answer:

A

Flatbed scanner often come with sheet feeders for scanning multiple sheets of paper rather than one at time

8 0
3 years ago
Read 2 more answers
Other questions:
  • You've been asked to design a soho network on a work place. the other offices in the building also have wireless networks. while
    7·1 answer
  • In Windows 2000 and later, the ____ command shows you the file owner if you have multiple users on the system or network.
    15·1 answer
  • Which remote access configuration option should you choose if you want mobile users to be able to make a secure connection to th
    9·2 answers
  • Can you please help me by sending a proposal onnanotechnology in networking applications
    8·1 answer
  • In Java please:Re-type the code and fix any errors. The code should convert non-positive numbers to 1. if (userNum &gt; 0) Syste
    10·1 answer
  • What would you need to have on your foley stage
    9·1 answer
  • Why don't I have friends?
    11·2 answers
  • Helllllllllppppppppppp
    9·1 answer
  • Which programming languages are the best choices for desktop applications? Select 3 options.
    8·2 answers
  • Get ready to be the Quizmaster! You are going to design your own Python game show in the style of a quiz.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!