Question

In: Computer Science

USING PYTHON. Thank you in advance Write a program that allows the user to enter a...

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

Solutions

Expert Solution

Implement the program as follows:

  1. initialize an empty list, string_list
  2. read first string, value from user
  3. repeat until value is not "done"
  4. append value to string_list
  5. read next string value from user
  6. initialize another empty list, new_palin_list
  7. for each value in string_list, append it to new_palin_list
  8. for each index in string_list, index varies from last to first
  9. add string_list[index] to new_palin_list
  10. print output message and print elements in new_palin_list

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.


Related Solutions

In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter his/her favorite English saying, then counts the number of vowels in that (note that the user may type the saying using any combination of upper or lower case letters). Example: Enter your favorite English saying: Actions speak LOUDER than words. Number of wovels: 10
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the...
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by that candidate. The program should then output each candidates name, votes received by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is as follow Johnson    5000 25.91 miller    4000   ...
Write a C++ program using dynamic arrays that allows the user to enter the last names...
Write a C++ program using dynamic arrays that allows the user to enter the last names of the candidates in a local election and the number of votes received by each candidate. The program must ask the user for the number of candidates and then create the appropriate arrays to hold the data. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should...
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Write a program using Python that allows the user to play a guessing game (please provide...
Write a program using Python that allows the user to play a guessing game (please provide a picture of code so it is easier to read). The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: Normally, we would have the program select a random number as the "secret number". However, for the purpose of testing your program (as well as grading it), simply use an assignment...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT