Maill 8:25 AM foothillcollege.instructure.com 87% with their classmates). FOOTHI
ID: 3599998 • Letter: M
Question
Maill 8:25 AM foothillcollege.instructure.com 87% with their classmates). FOOTHILI COLLEGE L A (rather informal) spec follows. Write a program called ChocolateReplacementTherapy. When I run it, it should prompt me to enter a noun (or noun phrase) of my liking. It should then select a random quote about chocolate from its bank of quotes (If you like you may use the quotes provided below to make up your bank), replace all occurrences of the word chocolate with my noun (or noun phrase) and print the revised quote. As an extra challenge, you could pay attention to the detail and make sure that the casing of the replaced word is preserved in the output. For example if I entered "Moon Dust Pixie Pie" in response to the prompt, a quote that had the word "Chocolate" may come out with Chocolate replaced by "Moon dust pixie pie" and a quote that had chocolate" (in lower case) might come out with the replacement "moon dust pixie pie" You may also choose to put the above user interaction into a loop so a user could keep experimenting with various replacements for Chocolate. Very therapeutic, yes?:- Implementation notes: Inbox Help You should store the list of quotes in an array of strings, select one of these strings randomly upon the users response, process it for replacement (A tip Don't replace words in place-make a brand new string from scratch appending words to it sequentially. Output this new string when done). Below you'll find a list of Chocolate related quotes. But of course, your program doesn't have to be about Chocolate. It Have fun and happy hacking.Explanation / Answer
import random quotes = [] inputFile = open("quotes.txt", "r") # Reading file for line in inputFile.readlines(): quotes.append(line) inputFile.close() choice = 'YES' while choice.upper() == 'YES': # if user wants phrase = raw_input('Enter a noun or phrase: ') quote = quotes[random.randint(0, len(quotes))] # choosing random quote i = 0 print 'Rephrased quote: ', while quote.lower().find('chocolate', i) != -1 and iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.