Answer to Question #270974 in Python for Chiarra

Question #270974

String Replacement

by CodeChum Admin

Lists are fun to make, but it's even better to add or remove things from it when it's not usable anymore, right? Let's do just that in this problem now!


Instructions:

  1. Create two variables that will accept string values.
  2. A list containing three string values is already given to you in the code editor on the side. First, insert the first inputted string to the end of the list.
  3. Then, insert the second inputted string into the beginning of the list.
  4. There are now 5 elements on the given list. Now, remove the 4th element of the list. Apply the concept of index positions in order to access the 4th string element and successfully remove it from the list.
  5. Print out the remaining contents on the list, each separated by a new line, using loops.

Input

Two lines containing a string.

fun
Python

Output

A line containing a string.

Python·is·really·fun
1
Expert's answer
2021-11-25T07:54:03-0500
# create two variables and accept string values
first = input()
second = input()

# a list containing three string values
L = ["is", "realy", "good"]

# Insert the first inputted string to the end of the list
L.append(first)

# Insert the second inputted string into the beginning of the list
L.insert(0, second)

# Remuce the 4th element of the list (its index is 3)
L.pop(3)

# Print out the remaining contents on the list, using loop
for s in L:
    print(s, end=' ')
    
print()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS