string prgs
string prgs
txt='DIvIsiBiLItY'
count=0
for i in txt:
if i.lower()=='i':
count+=1
print(count)
#Replace ‘i’ with space. (try with replace function and without replace function)
-----------------------------------------
#replace i with space
txt='DIvIsiBiLItY'
txt1=''
count=0
for i in txt:
if i.lower()=='i':
count+=1
txt1+=' '
else:
txt1+=i
print(txt1)
-------------------------------------------
#Separate each character with ‘$’
txt='DIvIsiBiLItY'
for i in txt:
print(i,end="$")
-----------------------------------
#Convert uppercase case letters to lowercase or vice verse
txt='DIvIsiBiLItY'
txt1=''
for i in txt:
if 'a'<i<'z':
txt1+=chr(ord(i)-32)
else:
txt1+=chr(ord(i)+32)
print(txt1)
--------------------------------------------
#Read a string “A cat sat on the mat near an open window,
#watching a bird on the fence.” Count no. of articles
txt="A cat sat on the mat near an open window,watching a bird on the fence."
txtL=txt.lower()
txt_list=txtL.split(" ")
art=['a','an', 'the']
count=0
for i in txt_list:
if i in art:
count+=1
print(count)
----------------------------------------------
#count no. of vowels
txt="A cat sat on the mat near an open window,watching a bird on the fence."
txtL=txt.lower()
vow="aeiou"
count=0
for i in txtL:
if i in vow:
count+=1
print(count)
--------------------------------------------
#count no, of words
txt="A cat sat on the mat near an open window,watching a bird on the fence."
txtL=txt.lower()
txt_list=txtL.split(" ")
print(len(txt_list))