Question

In: Computer Science

Hello, ***We have to print the second list backward while interleaved with the first list in...

Hello,

***We have to print the second list backward while interleaved with the first list in normal order.***

its PYTHON language.

Please refer the below example. Bold are the inputs that the user enters. In here the user input words and much as he wants and when he enter STOP, it stops and he is asked to enter more words.(second words count equals to the word count he inputs in the first phase)

Enter words, STOP to stop. Ok

Enter words, STOP to stop. we're

Enter words, STOP to stop. this

Enter words, STOP to stop. STOP

Ok. Now enter 3 other words.

Word 0: again?

Word 1: doing

Word 2: wait

Now I will magically weave them more weirdly!

Ok

wait

we're

doing

this

again?

PS : I have done it actually but the I have a problem getting the last output.(how to merge the 2 lists.) It only prints the words in input order.

MY CODE :

firstlist = []
c=0
stop = False

while not stop:
    a = input("Enter words, STOP to stop. : ")
    if a == "STOP":
        stop = True
    else:
        c+=1
        firstlist.append(a)


print("Okay. Now enter other " + str(c) +" numbers!")

for i in range(c):
    v = input('Enter word ' + str(i+1) + ': ' )
    firstlist.append(v)

print("I'm going to magically weave the words!!")

for x in firstlist:
    print(x)

Please help.

Solutions

Expert Solution

firstlist = []
c=0
stop = False

while not stop:
a = input("Enter words, STOP to stop. : ")
if a == "STOP":
stop = True
else:
c+=1
firstlist.append(a)


print("Okay. Now enter other " + str(c) +" numbers!")

secondlist = [] # TAKE a new list
for i in range(c):
v = input('Enter word ' + str(i+1) + ': ' )
secondlist.append(v) # put elements in that new list

print("I'm going to magically weave the words!!")

# loop for c times
last = c-1
for i in range(c):
print(firstlist[i]) # print first list from first
print(secondlist[last]) # print second list from last
last = last - 1 # decrement index of second list by 1

''' OUTPUT
Enter words, STOP to stop. : Ok
Enter words, STOP to stop. : We're
Enter words, STOP to stop. : This
Enter words, STOP to stop. : STOP
Okay. Now enter other 3 numbers!
Enter word 1: again?
Enter word 2: doing
Enter word 3: what
I'm going to magically weave the words!!
Ok
what
We're
doing
This
again?
'''

# hit the thumbs up if you are happy!


Related Solutions

While no longer used by the development community, the classification of countries into first, second, and...
While no longer used by the development community, the classification of countries into first, second, and third world status was used historically. What was the basis of this classification? What does this tell us about the role of geopolitics and foreign policy in the development community?
Print "Hello World" in the most complicated way (java)
Print "Hello World" in the most complicated way (java)
1. Find and print the length of the list listTest. 2. We can test if an...
1. Find and print the length of the list listTest. 2. We can test if an item exists in a list or not, using the keyword in It will give you a boolean response if a certain element is present. Find whether 'p' or 'P' is present in listTest, and print the results. Print results first for 'p' and then for 'P' as shown in example below. For example: Test Result listTest=['c','i','s','c','1','0','6','P','y','t','h','o','n'] False True 3. We can delete one or...
A mother has two children. The first was born perfectly healthy while the second one was...
A mother has two children. The first was born perfectly healthy while the second one was born with rashes, showed clumping and lysis of blood. Based upon this information how would you classify this disorder? What type of antibody-antigen interaction is this and why? Explain how this disorder arises.
Hello, I Have create this code and Tried to add do while loop but it gives...
Hello, I Have create this code and Tried to add do while loop but it gives me the error in string answar; and the areas where I blod So cloud you please help me to do ( do while ) in this code. // Program objective: requires user to input the data, program runs through the data,calcualtes the quantity, chacks prices for each iteam intered,calautes the prices seperatly for each item, and calculates the amount due without tax, and then...
7. A mother has two children. The first was born perfectly healthy while the second one...
7. A mother has two children. The first was born perfectly healthy while the second one was born with rashes, showed clumping and lysis of blood. Based upon this information how would you classify this disorder? What type of antibody-antigen interaction is this and why? Explain how this disorder arises
Hello, I have been struggling with the problem for a while now. Can someone please assist?...
Hello, I have been struggling with the problem for a while now. Can someone please assist? I cannot find the data online much less calculate the standard deviation. 1. Go to finance.yahoo.com and find them monthly rates of return over a 2 year period for five companies of your choice. Now assume you form each month an equally weighted portfolio of five firms (a portfolio with equal investments in each firm). What is the rate of return each month on...
import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(")...
import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(") " + entry) return int(input(question)) plz explain this code
We are gong to have a respectful and robust debate on the Second Amendment and Gun...
We are gong to have a respectful and robust debate on the Second Amendment and Gun Control. Discuss the controversy surrounding gun ownership, gun control legislation, and registration laws? Do you think gun control laws can effectively reduce violent crime?
1.) First answer = first blank; second answer = second blank. The test statistic for an...
1.) First answer = first blank; second answer = second blank. The test statistic for an ANOVA is a ratio of values and is noted by (F). In independent- measures ANOVAs, ________ comprises the numerator of this ratio, whereas ________ comprises the denominator of this ratio. A: systematic treatment effects and unsystematic effects; unsystematic effects B: systematic treatment effects; unsystematic effects C: unsystematic effects; systematic effects and unsystematic effects D: unsystematic effects; systematic effects 3.) Please select all that apply....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT