In: Computer Science
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.
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: