(1) the text file how many line?
(2) the file begins with a capital letter P how many lines?
(3) contains characters in a line up and contain characters which line the least respectively?
Such as: notepad content is:
A lot of people today are animal rights advocates.
Some of them are very
Passionate and even quite radical about the issue.
But others it that "human rights" will always
Take priority. In fact, In many places even
The most basic human rights are not adequately
Protected. So according to animal rights? What do you
Think? And why?
Running results as follows: the text file with a total of eight lines
The file begins with a capital letter P line 2
Contains the character is one of the most line 1
Contains the character is the least line 8
CodePudding user response:
Def line () :F=open (" E: \ \ School three \ \ \ \ Python \ \ the tenth week \ \ second TXT ", 'r')
Lines=f.r eadlines ()
Count=len (lines)
Print (" this text file consists of: ", count, "line")
Def search () :
F=open (" 2. TXT ", 'r')
Lines=f.r eadlines ()
N=0
For the line in lines:
If the line [0]=='T' :
N=n + 1
Print (" files begin with a capital letter T have ", n, "line")
Def r () :
F=open (" English. TXT ", 'r')
Lines=f.r eadlines ()
L=[]
For I in lines:
Num=len (i. trip ())
L.A. ppend (num)
Print (" characters in a line up in the first ", l.i ndex (Max) (l) + 1, "line")
Print (" the least in the first character of a line ", l.i ndex (min (l)) + 1, "line")
The line ()
Search ()
R ()