First attempts

From XPUB & Lens-Based wiki
Revision as of 15:25, 4 October 2015 by SN (talk | contribs) (Created page with "OMG! My weird code works! (P.S. It works in Python 2.7) longest = None smallest = None text = raw_input('Enter some text:') words = text.split() number = len(words) tota...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

OMG! My weird code works! (P.S. It works in Python 2.7)

longest = None
smallest = None
text = raw_input('Enter some text:')
words = text.split()
number = len(words)
total = 0
for word in words:
	summa = total + len(word)
	total = summa
	while longest is None or len(word) > len(longest):
		longest = word
	while smallest is None or len(word) < len(smallest):
		smallest = word
print 'number of words:', number
print 'longest word is:', longest
print 'smallest word is:', smallest
print 'avarage word lenght is:', float(summa)/number
print 'end of program'