'I need help defining a specific word in the text file
Part 2 Specific Word Count:
Hi, I have 3 parts that I am doing to this program and so far I have the first one which is wordcount. Part 2 is the specific word count and while I am able to put it in one of the elif statements, the requirement is to define it. I want to know how to define a specific input such as "ship" from a text file into my "Specific Word Count" where it says "print(2)"
Part 3 Find the Message:
If you can also help with this part this would be nice too. I'm looking for a secret message in the text file that is between 2 @ symbols and I want to print what is between those 2 @ symbols. The condition is also having to define it. I have tried a few things but so far no luck as well. This is what I have so far that has a word and I have tested all the if, elif, and else statements.
#################################################
from http.client import LineTooLong
import string
def display_menu():
print( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@" )
print( "@ 1 Total Word Count @" )
print( "@ 2 Specific Word Count @" )
print( "@ 3 Find The Message @" )
print( "@ 4 Exit @" )
print( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@" )
option = input('Enter your selection > ')
return option
##################################################
x = display_menu()
count = 0
def get_word_count( handle_input ):
handle_input.seek(0)
lines = 0
count = 0
for line in handle_input:
words = len(line.split())
count= count + words
return(count)
def get_specific_count( handle_input):
handle_input.seek(0)
def find_message( handle_input ):
handle_input.seek(0)
return(0)
while x != '4':
if x == '1':
fhand = open('Moby Dick.txt')
y = get_word_count(fhand)
print("Total:"+ str(y))
elif x == '2':
print(2)
elif x == '3':
print(3)
else:
print('Error try again!')
x = display_menu()
This is a Sample of what the Text file looks like since I cant attach a file
CHAPTER 1
Loomings.
Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people's hats off--then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
