Day 10 Live PDF
Day 10 Live PDF
IMPORTANT QUESTION
CHAPTER EXPLANATION
By : ANAND SIR, YOUTUBE CHANNEL: CODEITUP
TEXT FILES | PART 02
E X P L A N A T I O N B Y : A N A N D S I R , Y O UT UB E C H A N N E L : C O D E I T UP
TEXT FILES | PART 02
E X P L A N A T I O N B Y : A N A N D S I R , Y O UT UB E C H A N N E L : C O D E I T UP
TEXT FILES | PART 02
E X P L A N A T I O N B Y : A N A N D S I R , Y O UT UB E C H A N N E L : C O D E I T UP
#read the content of a file called "student.txt" #using readline function
f=open("student.txt","r") f=open("student.txt","r")
data=f.read() data=f.readline()
print(data) print(data,end='')
f.close() data=f.readline()
print(data,end='')
f.close()
#Program 3: Count total vowels and consonants #Program 3: Print last line
f=open("student.txt") f=open("student.txt")
data=f.read() data=f.readlines()
v=c=0 print(data[-1])
for i in data: f.close()
if i.isalpha():
if i in 'aeiouAEIOU':
v+=1
#count total sentences.
else:
f=open("student.txt")
c+=1
count=0
print("Total Vowels=",v,"Total COns=",c)
data=f.read()
f.close()
for i in data:
if i=='.':
count+=1
print("total Number of Sentences=",count)
TEXT FILES | PART 02
E X P L A N A T I O N B Y : A N A N D S I R , Y O UT UB E C H A N N E L : C O D E I T UP
#Program 3: Find no of words in a file 'student.txt' #Program 3: Count total vowels and consonants
f=open("student.txt") f=open("student.txt")
data=f.read() data=f.read()
data1=data.split() v=c=0
print(data1) for i in data:
print("Total number of Words=",len(data1)) if i.isalpha():
f.close() if i in 'aeiouAEIOU':
v+=1
else:
c+=1
#Program 2: Find no of lines in a file 'student.txt' print("Total Vowels=",v,"Total COns=",c)
f=open("student.txt") f.close()
data=f.readlines()
print("Total number of lines=",len(data))
f.close()
TEXT FILES | PART 02
E X P L A N A T I O N B Y : A N A N D S I R , Y O UT UB E C H A N N E L : C O D E I T UP