(PP-3)
3A.Write a program to replace all occurrences of character ‘a’ with ‘$’ sign in a string.
str="My name is SK"
x=str.replace("a","$")
print(x)
OR
str="My name is SK"
x=str.replace(" ","-")
print(x)
3B.Write a python program to count number of vowels in a string.
str="hello world"
count=0
for i in str:
if (i=="a" or i=="A" or i=="e" or i=="E" or i=="i" or i=="I" or i=="o" or i=="O" or i=="u" or i=="U"):
count+=1
print(count)
3C.Write a python program to remove characters of odd index value in string
def odd_values(str):
result=" "
for i in range(len(str)):
if i%2==0:
result+=str[i]
return result
print(odd_values("abcdef"))
3D.Write a python program to check whether two strings are anagrams.
def check(s1,s2):
if (sorted(s1)==sorted(s2)):
print("The strings are anagrams")
else:
print("The strings are not anagrams")
s1="silent"
s2="listen"
check(s1,s2)
3E.Write a python program
to count no of lowercase characters in a string.
string="hello world"
count=0
for i in string:
if(i.islower()):
count+=1
print("The number of lowercase characters is:",count)
3F.Write a python program to check if string is pangram or not.
import string
def ispangram(str):
alphabet="abcdefghijklmnopqrstuvwkyz"
for char in alphabet:
if char not in str.lower():
return False
return True
string="The quick brown fox jumps over the lazy dog"
if(ispangram(string)==True):
print("Yes")
else:
print("no")
Comments
Post a Comment