Search This Blog

Thursday, 18 November 2021

Read a text file and display the number of vowels/consonants/uppercase/lowercase ,characters in the file

 Read a text file and display the number of vowels/consonants/uppercase/lowercase, characters in the file

f=open("poem.txt","r")
vowels='aeiouAEIOU'
v=0
c=0
u=0
l=0
for i in f.read():
if i.isalpha():
if i.isupper():
u=u+1
else:
l=l+1
if i in vowels:
v=v+1
else:
c=c+1
print("Vowels=",v)
print("consonants=",c)
print("uppercase letters=",u)
print("lowercase letters=",l)
f.close()



Output:-
Vowels= 16
consonants= 24
uppercase letters= 1
lowercase letters= 39

No comments:

Post a Comment

how to implement YOLOv3 using Python and TensorFlow

Object Detection with YOLOv3 Introduction YOLOv3 (You Only Look Once version 3) is a real-time object detection algorithm that can detect ob...