[Tutor] Hi All
Morne
Morne" <fromclay@maxitec.co.za
Thu, 22 Aug 2002 13:42:14 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_006C_01C249E1.B93C4800
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi could one or 2 of you help me with this I have gotten this far I =
havnt got the hang of python yet but am working on it .
Here it goes:
def getStuff(file)
info =3D open(file,"r")
infolines =3D info.readlines()
for line in infolines:
word =3D string.split(lines)
print"Line %d contains %d words" % (linenum,len(word))
linenum +=3D 1
totalwords +=3D len(words)
print "Total lines:", linenum - 1
print "Average words per line:", float(totalwords)/linenum - 1
file =3D raw_input("Enter the filename: ")
getStuff(file)
Here is what I want it to do it takes a text file and counts the number =
of
lines in the file, the number of words in a line and then produces a
summary. The Output must look like this.
Enter file name:
> testfile.txt
LINE# WORDS
--------------------
1 20 words
2 25 words
3 30 words
4 25 words
--------------------
Summary:
4 lines, 100 words, Avg: 25 words/line
=20
Can you pease let me know if this is right and if not "what the errors =
are and how to fix them
I have until tomorrow and then my boss wants me to show him what I know =
he has given me 5 days to do this and I used python for the first time =
on Monday. And I will be asking you all alot more questions.
Thanx From morne
------=_NextPart_000_006C_01C249E1.B93C4800
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>Hi could one or 2 of you help me with =
this I have=20
gotten this far I havnt got the hang of python yet but am working on it=20
.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Here it goes:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>def getStuff(file)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> info =3D=20
open(file,"r")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> infolines =3D=20
info.readlines()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> for line in=20
infolines:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> word =3D=20
string.split(lines)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> print"Line %d =
contains %d words"=20
% (linenum,len(word))</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> linenum +=3D =
1</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> totalwords +=3D=20
len(words)<BR> print "Total lines:", linenum -=20
1<BR> print "Average words per line:",=20
float(totalwords)/linenum - 1<BR>file =3D raw_input("Enter the filename: =
")<BR>getStuff(file)<BR><BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Here is what I want it to do it takes a =
text file=20
and counts the number of<BR>lines in the file, the number of words in a =
line and=20
then produces a<BR>summary. The Output must look like=20
this.<BR><BR><BR>Enter file name:<BR>> =
testfile.txt<BR><BR><BR>LINE# =20
WORDS<BR>--------------------<BR>1 20=20
words<BR>2 25=20
words<BR>3 30=20
words<BR>4 25=20
words<BR>--------------------<BR>Summary:<BR>4 lines, 100 words, Avg: 25 =
words/line<BR></DIV></FONT>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Can you pease let me know if this is =
right and if=20
not "what the errors are and how to fix them</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I have until tomorrow and then my boss =
wants me to=20
show him what I know he has given me 5 days to do this and I used python =
for the=20
first time on Monday. And I will be asking you all alot more=20
questions.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanx From=20
morne</FONT></DIV></FONT></DIV></BODY></HTML>
------=_NextPart_000_006C_01C249E1.B93C4800--