Question

In: Computer Science

Jack just completed the program for the Flesch text analysis from this chapter’s case study. His...

Jack just completed the program for the Flesch text analysis from this chapter’s case study. His supervisor, Jill, has discovered an error in his code. The error causes the program to count a syllable containing consecutive vowels as multiple syllables.

Suggest a solution to this problem in Jack’s code and modify the program so that it handles these cases correctly.

An example text and the program input and output is shown below:

example.txt

Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep.

Enter the file name: example.txt
The Flesch Index is 102.045
The Grade Level Equivalent is 1
3 sentences
18 words
21 syllables

"""
Program: textanalysis.py
Author: Ken
Computes and displays the Flesch Index and the Grade
Level Equivalent for the readability of a text file.
"""

# Take the inputs
fileName = input("Enter the file name: ")
inputFile = open(fileName, 'r')
text = inputFile.read()

# Count the sentences
sentences = text.count('.') + text.count('?') + \
text.count(':') + text.count(';') + \
text.count('!')

# Count the words
words = len(text.split())

# Count the syllables
syllables = 0
vowels = "aeiouAEIOU"
for word in text.split():
for vowel in vowels:
syllables += word.count(vowel)
for ending in ['es', 'ed', 'e']:
if word.endswith(ending):
syllables -= 1
if word.endswith('le'):
syllables += 1

# Compute the Flesch Index and Grade Level
index = 206.835 - 1.015 * (words / sentences) - \
84.6 * (syllables / words)
level = int(round(0.39 * (words / sentences) + 11.8 * \
(syllables / words) - 15.59))

# Output the results
print("The Flesch Index is", index)
print("The Grade Level Equivalent is", level)
print(sentences, "sentences")
print(words, "words")
print(syllables, "syllables")

The given code needs to be edited to be correct. We are using the newest form of python.

Solutions

Expert Solution

Note:

#########

Here code is written to reduce the number of consecutive vowels from the total number of syllables. Those in Bold letters are the new code added

#################### PGM START #################################

#function to check a charcter is vowel or not
def is_vow(c):
    vowels = "aeiouAEIOU"
    for vowel in vowels:
        if c==vowel:
            return True
    return False

# Take the inputs
fileName = input("Enter the file name: ")
inputFile = open(fileName, 'r')
text = inputFile.read()

# Count the sentences
sentences = text.count('.') + text.count('?') + \
text.count(':') + text.count(';') + \
text.count('!')

# Count the words
words = len(text.split())

# Count the syllables
syllables = 0
vowels = "aeiouAEIOU"

for word in text.split():


    for vowel in vowels:      
        syllables += word.count(vowel)

    #decrease the count of consecutive vowels
    for i in range(1,len(word)):
        if(is_vow(word[i-1])==True and is_vow(word[i])==True):
            syllables-=1

  
    for ending in ['es', 'ed', 'e']:
        if word.endswith(ending):
            syllables -= 1
        if word.endswith('le'):
            syllables += 1

# Compute the Flesch Index and Grade Level
index = 206.835 - 1.015 * (words / sentences) - \
84.6 * (syllables / words)
level = int(round(0.39 * (words / sentences) + 11.8 * \
(syllables / words) - 15.59))

# Output the results
print("The Flesch Index is", index)
print("The Grade Level Equivalent is", level)
print(sentences, "sentences")
print(words, "words")
print(syllables, "syllables")

####################### PGM END ########################################

OUTPUT
##########


Related Solutions

Python Add a command to this chapter’s case study program that allows the user to view...
Python Add a command to this chapter’s case study program that allows the user to view the contents of a file in the current working directory. When the command is selected, the program should display a list of filenames and a prompt for the name of the file to be viewed. Be sure to include error recovery in the program. If the user enters a filename that does not exist they should be prompted to enter a filename that does...
Complete a case analysis of Ford (Case 17) (case study section of your text). A formal,...
Complete a case analysis of Ford (Case 17) (case study section of your text). A formal, in-depth case analysis requires you to utilize the entire strategic-management process. Assume your group is a consulting team asked by Ford to analyze its external/internal environment and make strategic recommendations. You will be required to make exhibits/matrices to support your analysis and recommendations. The case analysis must encompass 1-2 pages plus the reference page. The cover page must include the company name, your group...
Complete a case analysis of Ford (Case 17) (case study section of your text). A formal,...
Complete a case analysis of Ford (Case 17) (case study section of your text). A formal, in-depth case analysis requires you to utilize the entire strategic-management process. Assume your group is a consulting team asked by Ford to analyze its external/internal environment and make strategic recommendations. You will be required to make exhibits/matrices to support your analysis and recommendations. The case analysis must encompass 1-2 pages plus the reference page. The cover page must include the company name, your group...
James Kelvin just completed an Engineering Management degree program, main reason is to enhance his investment...
James Kelvin just completed an Engineering Management degree program, main reason is to enhance his investment capability. Now, he wants to take advantage of the falling prices of crude oil to invest in the oil business, with an anticipation that the prices will rise again. He has been offered an oil well with a proven reserve of 1800000 barrels. From his feasibility study, he will be able to produce 80,000 barrels of oil during the first year of operations. He...
Edited****There is not a case study. This is the question in the text.********* This question is...
Edited****There is not a case study. This is the question in the text.********* This question is in reference to the healthcare industry. Briefly describe what happens to each of the following as volume increases. Assume all values stay within their relevant range. Total fixed cost? Total variable cost? Fixed cost per unit? Variable cost per unit? Explain the relationship between step-fixed costs and the relevant range. References would be a bonus! This question is found on page 448 in Financial...
This case analysis relates to the case study, The details of the case study cover key...
This case analysis relates to the case study, The details of the case study cover key aspects of a financial report audit. For the purposes of this assignment, you are a senior auditor at Alex Gold Financial Services, an accounting firm. You have been assigned to the audit of Sheridan AV Ltd for the year ended 31 March 2021. The managing director of Sheridan AV, David Sheridan, is considering having Sheridan listed on the stock exchange and the Audit Partner,...
Case Study Neile looked at his mechanic and sighed. The mechanic had just pronounced a death...
Case Study Neile looked at his mechanic and sighed. The mechanic had just pronounced a death sentence on his road-weary car. The car had served him well---at a cost of $500 it had lasted through four years of college with minimal repairs. Now, he desperately needs wheels. He has just graduated, and has a good job at a decent starting salary. He hopes to purchase his first new car. The car dealer seems very optimistic about his ability to afford...
With reference to case study #8 from (total quality management and operational excellence text with cases...
With reference to case study #8 from (total quality management and operational excellence text with cases 4ed) book Case Name: Operational Excellence Driven by Process Maturity Reviews: A Case Study of the ABB Corporation Case study 8 Building quality and operational excellence across ABB COMPANY BACKGROUND AND HISTORY ABB is a global leader in power and automation technologies. Based in Zurich, Switzerland, the company employs 150,000 people and operates in approximately 100 countries. The firm's shares are traded on the...
I just finished this program where the program reads a text file of full names ,...
I just finished this program where the program reads a text file of full names , first and last name, and a zip code. It reads the items then stores the first name and last name and zipcodes as an objects and prints the items.   However, when i use my text file i get this error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 " I notice this issue only happens when the names are...
Case study. Just respond the questions at the end of the case study. SBAR Report: S:...
Case study. Just respond the questions at the end of the case study. SBAR Report: S: Mrs. Davis is an 85-year-old white female who was admitted last evening after falling and fracturing her hip. X-rays have been taken and show left intertrochanteric hip fracture. Mrs. Davis is scheduled for surgery in 2 days. B: Mrs. Davis has a 10-year history of osteoporosis and was newly diagnosed with congestive heart failure last year. Her daughter reports that recently Mrs. Davis has...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT