Discussion about this post

User's avatar
Pratik Dave's avatar

Ardit, this is superb exercise, not only the logic you have built to derive text statistics but how we write the code/program is absolutely amazing. Thanks!! This is how I want to write the code. I "cleaned" my dev.py and re-built and re-formatted entire code. Re-do is also part of learning process.

Expand full comment
Kuldeep sharma's avatar

def length_analyser(a):

b=len(a)

c=len(a.split(' '))

d=a.count(".") + a.count("?") + a.count("!")

test1=a.split(' ')

n=0

for i in test1:

n+=len(i)

return b ,c,d,n/len(test1),c/d

def freq_word(a):

test={}

test1=a.split(' ')

for i in test1:

test[i]=test1.count(i)

word=max(test,key=test.get)

return word , test[word]

x= input("enter a bloxk of text for analysis:")

char_count,word_count,line_count,avg_word_len,avg_sent_len=length_analyser(x)

z,f=freq_word(x)

print("Total number of charaters {}".format(char_count) )

print("Total number of words {}".format(word_count) )

print("Total number of lines {}".format(line_count) )

print("Most frequest word used is {} . it is used {} times".format(z,f) )

print("Average word length is {}".format(avg_word_len) )

print("Average sentence length is {}".format(avg_sent_len) )

Expand full comment

No posts

Ready for more?