Question
PLEASE HELP!!!!! PYTHON ONLY For this task, you will write a program that performs some analysis of the novel Alices Adventures in Wonderland by Lewis
PLEASE HELP!!!!! PYTHON ONLY
For this task, you will write a program that performs some analysis of the novel Alices Adventures in Wonderland by Lewis Carroll. First, please download the provided file alice.txt, which is the full text of the novel. Then, write a program called test2.py that reads the provided file and reports the following information about it:
The total number of words
The average number of words in a line (total number of words / total number of lines)
The line with the most words and the number of words in that line
Provide an interface that allows the user to type in a word to look up how many lines contain that word and to see up to the first ten such lines. If no lines contain that word, then your program must output Not found.
If no lines contain the users word, it is not enough for your program to output something like 0 lines contain alice (if alice was the users word). Your program must output Not found. |
Example of running the final program
Total number of words: 26466 Average number of words in a line: 7.355753196220122 Longest line has 16 words: Alice was not a bit hurt, and she jumped up on to her feet in a Enter word: Alice Alice was beginning to get very tired of sitting by her sister thought Alice `without pictures or conversation?' There was nothing so VERY remarkable in that; nor did Alice POCKET, and looked at it, and then hurried on, Alice started to In another moment down went Alice after it, never once and then dipped suddenly down, so suddenly that Alice had not a `Well!' thought Alice to herself, `after such a fall as this, I you see, Alice had learnt several things of this sort in her or Longitude I've got to?' (Alice had no idea what Latitude was, Down, down, down. There was nothing else to do, so Alice soon 392 lines contain Alice
Here are some additional examples of the output of step 5:
Enter word: alice Not found.
Notice above that the search is case-sensitive.
Enter word: adventure adventures.' `I could tell you my adventures--beginning from this morning,' `No, no! The adventures first,' said the Gryphon in an So Alice began telling them her adventures from the time when 4 lines contain adventure
Notice above that the search is for lines that contain the users word, not for exact matches of the word. So, even though the word the user entered above is 'adventure', the program shows lines with the word 'adventures', since 'adventure' is part of 'adventures'.
If you want to set up more than one condition for an if statement in your program, you can use an if statement after another if statement indented following it for as many conditions as you need. (In later units, you will learn another way to do this.) |
HELP ME!!!!!!
MY CODE NOW IS BELOW BUT I NEED TO ADD THE FEEDBACK GIVEN : "On the last part, if an inputted word appears in more than 10 lines, you should only be printing the first 10 lines that it appears in. You can do this by creating a new count variable, adding one to it every time you print a line and stop the printing once the count reaches "
lineList = [ ] maxLength=0 lineCount=0 numWords=0 maxWordsLine=""
# opening file alice.txt file = open('alice.txt')
# iterating through the lines of file for line in file: # counting lines lineCount += 1 # getting every line into lineList lineList.append(line) # splitting line to store words words = line.split() count = len(words) if(numWords==0): maxWordsLine=line maxLength = count if(maxLength # user word to search word = input(" Enter word: ") # count = 0 result = [] for line in lineList: if word in line: result.append(line) if len(result) > 0: for i in range(len(result)): # print lines contains user word print(result[i]) else: print("Not Found") print(len(result),"lines contain", word)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started