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 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 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
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...
Draw a structured flowchart or write pseudocode that describes the process of guessing a number between...
Draw a structured flowchart or write pseudocode that describes the process of guessing a number between 1 and 100. After each guess, the player is told that the guess is too high or too low. The process continues until the player guesses the correct number. Pick a number and have someone try to guess it by following your instructions. Submit the flowchart or pseudocode and the results of your test. Create a python program based on your flowchart or pseudocode....
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that...
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display the following data: The lowest number in the array. The highest number in the array. The total of the numbers in the array. The average of the numbers in the array. PLEASE AND THANK YOU
Suppose we have a substring of length m and text of size n. Write an algorithm...
Suppose we have a substring of length m and text of size n. Write an algorithm to find out if the substring is present in the text or not. What is the complexity of your algorithm in terms of m and n.
write on what are the principles of corporate governance in your own words with in text...
write on what are the principles of corporate governance in your own words with in text citations. also provide apa style citation below that
How to count the number of words that only show up once in a text file,...
How to count the number of words that only show up once in a text file, and replace those words with a character '(unique)' using Python? Without list is better.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT