import sys def vowel_Count(word): lower = word.lower() resultCount=len(lower.split('a')) + len(lower.split('e')) + len(lower.split('i')) + len(lower.split('o')) + len(lower.split('u')) -5 return resultCount line1 = "I pledge allegiance to the Flag of the United States of America,\n" line2 = "and to the Republic for which it stands, one Nation under God,\n" line3 = "indivisible, with liberty and justice for all, should be rendered\n" line4 = "by standing at attention facing the flag with the right hand over\n" line5 = "the heart. When not in uniform men should remove any non-religious\n" line6 = "headdress with their right hand and hold it at the left shoulder,\n" line7 = "the hand being over the heart. Persons in uniform should remain\n" line8 = "silent, face the flag, and render the military salute.\n" line = line1 + line2 + line3 + line4 + line5 + line6 + line7 + line8 lines = line.splitlines() i=0 linecount = 0 wordcount=0 lineinterval = 2 wordinterval = 3 vowelcount = 2 for l in lines: linewordcount = 0 i=i+1 if i%lineinterval == 0: words = l.split(' ') j=0 for w in words: j=j+1 if j%wordinterval != 0: continue result = vowel_Count (w) if result >= vowelcount: linewordcount = linewordcount +1 if linewordcount > 0: linecount = linecount +1 wordcount = wordcount + linewordcount print "Line count: %d, Word count: %d" % (linecount, wordcount)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question