Question

In: Computer Science

1)Write pseudocode for calculating the average text length (in number of words) for NLTK corpus 2)...

1)Write pseudocode for calculating the average text length (in number of words) for NLTK corpus

2) Write Python code for your average-text-length pseudocode.

Solutions

Expert Solution

1.Psudo code:

string=reading string from the user
words=split the string into words
lenght=0
for every word in words list:
lenght+=len(word)
calculating the sum of lengths of all words
print(lenghts of all words/no of words)

Here string is NLTK corpus

now we split the string

words=[NLTK,corpus]

length=0

length=len(NLTK)+len(corpus)

length=4+6

length=10

lenght/no of words=10/2

average word length=5

2.Code:

string=input("Enter a string to find the average word length: ")
#readingstring from the user
words=string.split()
#spliting the strings into words
length=0
#intially we put the length as 0
for word in words:
length+=len(word)#Here we caculate the sum of the lengths of the words
print("Average Word Length: ",length/len(words))
#Here we calculate the average word lengh

Output:

Indentation:


Related Solutions

Write a Python program that will process the text file, Gettysburg.txt, by calculating the total words...
Write a Python program that will process the text file, Gettysburg.txt, by calculating the total words and output the number of occurrences of each word in the file. The program needs to open the file and process each line. You need to add each word to the dictionary with a frequency of 1 or update the word’s count by 1. You need to print the output from high to low frequency. The program needs 4 functions. The first function is...
Write a C program to find out the number of words in an input text file...
Write a C program to find out the number of words in an input text file (in.txt). Also, make a copy of the input file. Solve in C programming.
Java Write a method that reads a text file and prints out the number of words...
Java Write a method that reads a text file and prints out the number of words at the end of each line
Write a program that implements the pseudocode below: 1. Ask the user for the number of...
Write a program that implements the pseudocode below: 1. Ask the user for the number of days until finals. 2. Print out the weeks until finals (weeks = days // 7) 3. Print out the leftover days (leftover = days % 7) Note: Always have some labeling (identifying) text to explain the meaning of any numbers printed. And, do not forget to have your name and what the program does as comments in the beginning of your file.
Create pseudocode for a program for Stumpy's Cell Phone Company that accepts the number of text...
Create pseudocode for a program for Stumpy's Cell Phone Company that accepts the number of text messages for a customer for one month and displays the bill for text messages. If the user enters a negative number the program should display an error message. If the user enters number greater than or equal to 0 your program should call a function that given the number of text messages, returns the amount to be charged. The program will then display a...
Write pseudocode for a function that translates a telephone number with letters in it (such as...
Write pseudocode for a function that translates a telephone number with letters in it (such as 1-800-FLOWERS) into the actual phone number. Use the standard letters on a phone pad
Write a python program that calculates the average number of words per sentence in the input...
Write a python program that calculates the average number of words per sentence in the input text file. every sentence ends with a period (when, in reality, sentences can end with !, ", ?, etc.) and the average number of sentences per paragraph, where a paragraph is any number of sentences followed by a blank line or by the end of the text.
in javascript, Write a method for calculating (and returning) the total length of all songs in...
in javascript, Write a method for calculating (and returning) the total length of all songs in the playlist. Do not use indexes or a for-each loop (those would be perfectly fine ways to solve the problem, but we want to practice another way).
● Write a program that reads words from a text file and displays all the words...
● Write a program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. Must use ArrayList. MY CODE IS INCORRECT PLEASE HELP THE TEXT FILE CONTAINS THESE WORDS IN THIS FORMAT: drunk topography microwave accession impressionist cascade payout schooner relationship reprint drunk impressionist schooner THE WORDS MUST BE PRINTED ON THE ECLIPSE CONSOLE BUT PRINTED OUT ON A TEXT FILE IN ALPHABETICAL ASCENDING ORDER...
● Write a program that reads words from a text file and displays all the words...
● Write a program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. Must use ArrayList. THE TEXT FILE CONTAINS THESE WORDS IN THIS FORMAT: drunk topography microwave accession impressionist cascade payout schooner relationship reprint drunk impressionist schooner THE WORDS MUST BE PRINTED ON THE ECLIPSE CONSOLE BUT PRINTED OUT ON A TEXT FILE IN ALPHABETICAL ASCENDING ORDER IS PREFERRED THANK YOU IN ADVANCE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT