Class 11 Important Python String Programs
Q21. Write a program to accept a string and display the string with second alphabet of each word in upper case.
Ans. str = input("Enter any String") str1 = "" L=str.split( ) for i in L: str1 = str1 + i[0] + i[1].upper() + i[2:] +" " print(str1)
Q22. 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)
Q23. 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)
Q24. Write a program to accept any string from the user and display it in the following pattern
if the string entered is “Python String Programs” then the output should be
Python Python String Python String Programs
Ans. str = input("Enter any string") L=str.split() str1 = "" for i in L: str1 = str1 + i print(str1)
Q25. 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)
Q26. Write a program to accept a string and substring from the user and display the frequency of substring in string.
Ans. str = input("Enter any string") substr=input("Enter any substring") print(str.count(substr))
Q27. Write a program to replace all ‘a’ in a string by symbol ‘@’.
Ans. str = input("Enter any string") str1="" for i in str: if i!='a': str1=str1+i else: str1=str1+'@' print(str1)
Q28. Write a program to accept a string and substring from the user and check whether the substring is existing/present in string or not.
Ans. 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")
Q29. Write a program to accept a string from the user and display n characters from the right of the string. (Accept n from the user)
A n s. str = input("Enter any string") n=int(input("Enter number of characters to be extract from right")) L = len(str) if n > L: print("Enter less number of characters") else: print(str[-n:])
Q30. Write a program to accept a word from the user and display it in the following pattern.
if the word is “river” then it should display as shown below
r r i r i v r i v e r i v e r
A ns. str = input("Enter any string") str1 = "" for i in str: str1 = str1 + i print(str1)
Disclaimer : I tried to give you the correct code of all the python string programs, but if you feel that there is/are mistakes in the python string programs given above, you can directly contact me at csiplearninghub@gmail.com. Also Share your valuable feedback about the above Python String Programs or any other suggestion so that I can give better content to you.
Class 12 Computer Science Sample Paper 2020-2021.
Class 12 Computer Science Sample Paper Marking Scheme
CBSE Class 12 Board Exam Date Sheet 2020-21








