[Tutor] hELP!!!!!!!!!!!!!!!
python
python <python@inkedmn.net>
Tue, 20 Aug 2002 16:15:17 -0700
hello,
this works:
# line/word counter
def getStuff(file):
info = open(file, 'r')
infolines = info.readlines()
linenum = 1
for line in infolines:
words = line.split(' ')
print "Line %d contains %d words" % (linenum, len(words))
linenum += 1
file = raw_input("Enter the filename: ")
getStuff(file)
best of luck,
brett
M> Hi Sir
M> Could you please help me with thise task Im new to Python and want to learn alot more,If you could help me I would very much Like that.
M> How would I create a Python program that takes a text file and counts the number of
M> lines in the file, the number of words in a line and then produces a
M> summary. The Output must look like this.
M> Enter file name:
>> testfile.txt
M> LINE# WORDS
M> --------------------
M> 1 20 words
M> 2 25 words
M> 3 30 words
M> 4 25 words
M> --------------------
M> Summary:
M> 4 lines, 100 words, Avg: 25 words/line
M> From Morne
--
Best regards,
python mailto:python@inkedmn.net