Question: Question: Need help debugging program, program not looping properly and going to the correct choice after entering A,B,C,E when asked for story and at end

Question: Need help debugging program, program not looping properly and going to the correct choice after entering "A,B,C,E" when asked for story and at end when asked if they would like to search for another term. Could you help to see where the problems in my code are and how to fix please.

additional info: I have 3 text files of stories saved in separate files that i am calling to open; file names(peter_rabbit, jimmy_rabbit, mother_goose)

instructions from teacher

Question: Need help debugging program, program not looping properly and going to

**************CODE***************** # import texts and open files / use, try exception statement import sys def readFile(fname): try: f = open(fname,'r',encoding="utf-8") except: print("Couldn't find the book in our library") sys.exit() # break string into lists words = f.read().split() f.close() return words

def search(text,word): return text.count(word)

main = [] print("******** Welcome to the Gutenberg Story Word Count Program*******") while(True): #option to pick between stories story = input("Choose from the list of childrens stories below: A- The Tale of Jimmy Rabbit B- The tale of Peter Rabbit C- Mother Goose E- Exit ") print()

story = story.upper() if story.lower() == "a": print("You have selected: A Tale of Jimmy Rabbit") name = 'Jimmy' fname = 'jimmy_rabbit.txt' elif story.lower() == "b": print("You have selected: A Tale of Peter Rabbit") name = 'peter' fname = 'peter_rabbit.txt' elif story.lower() == "c": print("You have selected: Mother Goose") name = 'mother' fname = 'mother_goose.txt' elif story.lower() == "e": print("Thank You for using the Word Count program, Goodbye!") #break sys.exit() # validate user input else: print("Invalid entry. Please try again") print() # Ask user for search term, output number of occurances while(True): term = input("Enter your search term: ") print() words = readFile(fname) print(name+" has about "+str(len(words))+" words") count = search(words,term) print("The search term "+term+" was found "+str(count)+" times") main.append([name,term,count]) print(" Your searches: ") for i in main: print("BOOK :",i[0]) print("SEARCH TERM :",i[1]) print("RESULTS :",i[2]) print() # ask if the user would like to search the story again. ch = input("Would you like to search again (y)? ") if(ch.lower()=='n'): break

Step Twoc Create Program that meets these requirements - Crese a gretinquila is yau pagan d yolw cutput. a pooltye noura incomect. - Once a dary is un weted, un a try cecupden viterent to check tut yeu con apen the file. Dutpat - "Gory that storystr = -Mangti was far and for through the forsut, rurning hard, and his heart wex hat in him. Ho case to he ceve as the eventing mat roas, end dren breath, and leoked down the vallay. The aud mere out, but Mother Matf, at the back of the car krew lay his breathing that somathing was troubting her frog.' storyards - starystr-aplito the tatal narker of worti in the fle. conplesily. Guterbare Stery Mard Countar Pragran Plecue choose fron on of the starien beler: A - Trarkenstein (1is) E. - The Strange Case af De. Jekyplt and Mr. Hyde (13se) C - The Tun of the Seren (1iss) E - Exit Pragra Yaur chosce: 4 Greet, w witt wark with Vrarkenstein. Liter your seerch terme stranga Trerkenstein has about 74975 mards. The search term strangu was found is times in Irenkenatein. Yaur suerches: Nautd you tike to wearch agatn (w ing y Enter your aeerch tern: dhild Trenkenstein has about 74975 mards. The search term dhs ld wex faund 1e tires in Vrankenstein. Your suerches: Nauld you tike ta wearch agati ( frnj)? n Plesue choose from ons of the staries belor: A - Trarkenstein (181.) D. - The Strange Case of De. lekylt and Mr. Hyd (13se) C. The Tun of the Seren (1ios) E. Exit Pragrom Yaur chosce: t Therk youl Gesdbyn

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!