Chapter - 9 String Manipulation Programs using built-in function
Chapter - 9 String Manipulation Programs using built-in function
2. Write a program to accept string and display total number of alphabets using in-
built function.
3. Write a program to accept a string and display the sum of the digits, if any
present in string using built-in function
for example: input string : My position is 1st and my friend come on 4th
for i in string:
if i.islower():
Lcount=Lcount+1
if i.isupper():
Ucount=Ucount+1
6. Write a program to accept a string and display each word and it's length.
7. Write a program to accept a string and display string with capital letter of each
word. for example, if input string is : welcome to my blog
output string : Welcome To My Blog
8. Write a program to replace all the word 'do' with 'done' in the following string.
str1 = "I do you do and we all will do"
11. Write a function in python which accept a string as argument and display total
number of digits.
string = input("enter the string")
count=0
for i in string:
if i.isdigit():
count=count+1
13. Write a program to count the number of words in the input string.
14. Write a program to display the last word of the string accepted from user.
15. Write a program to accept a string and display the ASCII value of each
character.
str=input("Enter any String :")
for i in str:
print("ASCII value of ",i,"is",ord(i))
16. Write a program to accept a string and replace all spaces by ‘#’ symbol.
17. Write a program to accept a string and count the frequency of each vowel.
18. Write a program to accept a string and display the string in Title case. (first
alphabet of each word in upper case)
19. Write a program to accept a string and display the string with changed
case.(Change upper case alphabet to lower case and vice versa)
20. Write a program to accept a string and display the word which has vowel ‘a’ in
it.
Ans.
str = input("Enter any String")
L=str.split()
for i in L:
if 'a' in i:
print(i)
21. Write a program to accept the first name from the user and display it as much
times as its length.
Ans.
str = input("Enter first name")
for i in range(len(str)):
print(str)
22. Write a program to accept a string from the user and display the string without space.
Ans.
str = input("Enter any string")
str1=""
for i in str:
if i.isspace()==False:
str1=str1+i
print(str1)
23. Write a program to accept a string and substring from the user and display the
frequency of substring in string.
str = input("Enter any string")
substr=input("Enter any substring")
print(str.count(substr))
24. Write a program to accept a string and substring from the user and check whether the
substring is existing/present in string or not.
.
str = input("Enter any string")
substr=input("Enter any substring")
if (str.find(substr)!=-1):
print("Substring is present")
else:
print("Substring is not present")
25. Write a program that takes a string with multiple words and then capitalizes the first
letter of each word and forms a new string out of it.
26. Python Program to calculate the number of digits and letters in a string
string=input("Enter string:")
count1=0
count2=0
for i in string:
if(i.isdigit()):
count1=count1+1
if(i.isalpha()):
count2=count2+1