In: Computer Science
USING PYTHON. Thank you in advance
Write a program that allows the user to enter a series of string values into a list. When the user enters the string ‘done’, stop prompting for values. Once the user is done entering strings, create a new list containing a palindrome by combining the original list with the content of the original list in a reversed order.
Sample interaction:
Enter string: My
Enter string: name
Enter string: is
Enter string: Sue
Enter string: done
The palindrome is: My name is Sue Sue is name My
Implement the program as follows:
Program:
Note: Please double-check the indentation using the screenshot provided as a reference
string_list = [] # initialize an empty list, string_list
value = input("Enter string: ") # read first string, value from user
while value != "done": # repeat until value is not "done"
string_list.append(value) # append value to string_list
value = input("Enter string: ") # read next string value from user
new_palin_list = [] # initialize another empty list, new_palin_list
for value in string_list: # for each value in string_list, append it to new_palin_list
new_palin_list.append(value)
for index in range(len(string_list)-1, -1, -1): # for each index in string_list, index varies from last to first
new_palin_list.append(string_list[index]) # add string_list[index] to new_palin_list
print("The Palindrome is: ", end='') # print output message and print elements in new_palin_list
for value in new_palin_list:
print(value, end=' ')
Screenshot:
Output:
Please don't forget to give a Thumbs Up.