Skip to content

Instantly share code, notes, and snippets.

#This is the code for the question in the page
#http://pylearn.pbworks.com/Count-Lines
import sys
doc = open(sys.argv[1],'r')
count = 0
for line in doc:
count += 1
print "the number of lines are: ",count
#This is the code for the question in the page
#http://pylearn.pbworks.com/Count-Sentences
import sys
doc = open(sys.argv[1],'r')
text = doc.read()
linesplit = text.split('.')
print "the number of sentences are:",len(linesplit)-1
#This is the code for the question in the page
#http://pylearn.pbworks.com/Print-Parameters
import sys
for arg in sys.argv:
print arg
if len(sys.argv)-1:
print "The number of command line arguments are: ",len(sys.argv)-1
else:
text = raw_input("Enter a text ")
textsplit = text.split()
print "The word count is = ",len(textsplit)