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...
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,...
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...
Write a complete Python program that asks the user for a line of text (not just...
Write a complete Python program that asks the user for a line of text (not just a single word), and then tells the user whether the string is a palindrome (same forward and backward) if you ignore case and non-alphabetic characters. The following methods and functions may be useful: str.upper(), str.isalpha() -> bool, reversed(str) -> sequence, str.find(str) -> int, str.replace(str, str), str.center(int). Unless otherwise specified, they all return a string.
Q 1b18. Nico Case, the Industrial Engineer from Company, has just completed an experiment with five...
Q 1b18. Nico Case, the Industrial Engineer from Company, has just completed an experiment with five different scenarios. She has run her scenarios for five different replications, each of 12 months. She obtains the following output, which represents monthly throughput: Scenario 1 Scenario 2 Scenario 3 Scenario 4 Scenario 5 3993 3979 3965 4007 4052 3992 3999 3988 4006 4125 4007 4021 4017 3991 4013 4010 4015 3971 3995 4014 3988 4000 4025 3994 4042 19990 20014 19966 19993 20246...
ERP and Change Management at Nestlé – case study analysis Read the case study and answer...
ERP and Change Management at Nestlé – case study analysis Read the case study and answer the questions: A year after signing a $200 million contract with SAP and more than $80 million for consulting services and maintenance, HSBC securities in London, downgraded their recommendation on Nestlé SA stock. Although the Enterprise Resource Planning (ERP) project will probably provide long-term benefits, the concern was what short-term effect the project will have on the company. Nestlé Company’s goal is to build...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT