The NCERT Solutions for Class 11 Computer Science are of much importance in developing an in-depth grasp of the difficult concepts in students. Our Orchids International School diligent efforts include making all learning resources available to students for enriching experience. Particularly, Class 11 Computer Science Chapter 9 deals with the "Strings" data structure, which forms a fundamental part of Python programming.
The NCERT Solutions for Class 11 Chapter 8 : Strings are tailored to help the students master the concepts that are key to success in their classrooms. The solutions given in the PDF are developed by experts and correlate with the CBSE syllabus of 2023-2024. These solutions provide thorough explanations with a step-by-step approach to solving problems. Students can easily get a hold of the subject and learn the basics with a deeper understanding. Additionally, they can practice better, be confident, and perform well in their examinations with the support of this PDF.
Download PDF
Students can access the NCERT Solutions for Class 11 Chapter 8 : Strings. Curated by experts according to the CBSE syllabus for 2023–2024, these step-by-step solutions make Computer-Science much easier to understand and learn for the students. These solutions can be used in practice by students to attain skills in solving problems, reinforce important learning objectives, and be well-prepared for tests.
Consider the following string mySubject:
mySubject = "Computer Science"
What will be the output of the following string operations:-
print(mySubject[0:len(mySubject)])
print(mySubject[-7:-1])
print(mySubject[::2])
print(mySubject[len(mySubject)-1])
print(2*mySubject)
print(mySubject[::-2])
print(mySubject[:3] + mySubject[3:])
print(mySubject.swapcase())
print(mySubject.startswith('Comp'))
print(mySubject.isalpha())
The output of the given string operations are as follows:
Computer Science
Scienc
Cmue cec
e
Computer ScienceComputer Science
eniSrtpo
Computer Science
cOMPUTER sCIENCE
True
False
Consider the following string myAddress:
myAddress = "WZ-1,New Ganga Nagar,New Delhi"
What will be the output of following string operations :
print(myAddress.lower())
print(myAddress.upper())
print(myAddress.count('New'))
print(myAddress.find('New'))
print(myAddress.rfind('New'))
print(myAddress.split(','))
print(myAddress.split(' '))
print(myAddress.replace('New','Old'))
print(myAddress.partition(','))
print(myAddress.index('Agra'))
The output of the given string operations are as follows:
wz-1,new ganga nagar,new delhi
WZ-1,NEW GANGA NAGAR,NEW DELHI
2
5
21
['WZ-1', 'New Ganga Nagar', 'New Delhi']
['WZ-1,New', 'Ganga', 'Nagar,New', 'Delhi']
WZ-1,Old Ganga Nagar,Old Delhi
('WZ-1', ',', 'New Ganga Nagar,New Delhi')
Error .. Substring Not found
Write a program to input line(s) of text from the user until enter is pressed. Count the total number of characters in the text (including white spaces), total number of alphabets, total number of digits, total number of special symbols and total number of words in the given text. (Assume that each word is separated by one space).
Program:
userInput = input("Write a sentence: ")
#Count the total number of characters in the text (including white spaces)which is the length of string
totalChar = len(userInput)
print("Total Characters: ",totalChar)
#Count the total number of alphabets,digit and special characters by looping through each character and incrementing the respective variable value
totalAlpha = totalDigit = totalSpecial = 0
for a in userInput:
if a.isalpha():
totalAlpha += 1
elif a.isdigit():
totalDigit += 1
else:
totalSpecial += 1
print("Total Alphabets: ",totalAlpha)
print("Total Digits: ",totalDigit)
print("Total Special Characters: ",totalSpecial)
#Count number of words (Assume that each word is separated by one space)
#Therefore, 1 space:2 words, 2 space:3 words and so on
totalSpace = 0
for b in userInput:
if b.isspace():
totalSpace += 1
print("Total Words in the Input :",(totalSpace + 1))
OUTPUT:
Write a sentence: Good Morning!
Total Characters: 13
Total Alphabets: 11
Total Digits: 0
Total Special Characters: 2
Total Words in the Input: 2
Write a user defined function to convert a string with more than one word into title case string where string is passed as parameter. (Title case means that the first letter of each word is capitalised)
Program:
#Changing a string to title case using title() function
def convertToTitle(string):
titleString = string.title();
print("The input string in title case is:",titleString)
userInput = input("Write a sentence: ")
#Counting the number of space to get the number of words
totalSpace = 0
for b in userInput:
if b.isspace():
totalSpace += 1
#If the string is already in title case
if(userInput.istitle()):
print("The String is already in title case")
#If the string is not in title case and consists of more than one word
elif(totalSpace > 0):
convertToTitle(userInput)
#If the string is of one word only
else:
print("The String is of one word only")
OUTPUT:
Write a sentence: good evening!
The input string in title case is: Good Evening!
Write a function deleteChar() which takes two parameters one is a string and other is a character. The function should create a new string after deleting all occurrences of the character from the string and return the new string.
Program 1:
#deleteChar function to delete all occurrences of char from string using replace() function
def deleteChar(string,char):
#each char is replaced by empty character
newString = string.replace(char,'')
return newString
userInput = input("Enter any string: ")
delete = input("Input the character to delete from the string: ")
newStr = deleteChar(userInput,delete)
print("The new string after deleting all occurrences of",delete,"is: ",newStr)
OUTPUT:
Enter any string: Good Morning!
Input the character to delete from the string: o
The new string after deleting all occurrences of o is: Gd Mrning!
Program 2:
#deleteChar function to delete all occurrences of char from string without using replace() function
def deleteChar(string,char):
newString = ''
#Looping through each character of string
for a in string:
#if character matches, replace it by empty string
if a == char:
#continue
newString += ''
else:
newString += a
return newString
userInput = input("Enter any string: ")
delete = input("Input the character to delete from the string: ")
newStr = deleteChar(userInput,delete)
print("The new string after deleting all occurrences of",delete,"is: ",newStr)
OUTPUT:
Enter any string: Good Evening!
Input the character to delete from the string: o
The new string after deleting all occurrences of o is: Gd Evening!
Input a string having some digits. Write a function to return the sum of digits present in this string.
Program:
#sumDigit function to sum all the digits
def sumDigit(string):
sum = 0
for a in string:
#Checking if a character is digit and adding it
if(a.isdigit()):
sum += int(a)
return sum
userInput = input("Enter any string with digits: ")
#Calling the sumDigit function
result = sumDigit(userInput)
#Printing the sum of all digits
print("The sum of all digits in the string '",userInput,"' is:",result)
OUTPUT:
Enter any string with digits: The cost of this table is Rs. 3450
The sum of all digits in the string ' The cost of this table is Rs. 3450 ' is: 12
Write a function that takes a sentence as an input parameter where each word in the sentence is separated by a space. The function should replace each blank with a hyphen and then return the modified sentence.
Program:
#replaceChar function to replace space with hyphen
def replaceChar(string):
return string.replace(' ','-')
userInput = input("Enter a sentence: ")
#Calling the replaceChar function to replace space with hyphen
result = replaceChar(userInput)
#Printing the modified sentence
print("The new sentence is:",result)
OUTPUT:
Enter a sentence: Python has several built-in functions that allow us to work with strings.
The new sentence is: Python-has-several-built-in-functions-that-allow-us-to-work-with-strings.
The same task can also be accomplished without using the string.replace() function. The program for the same can be written as :
Program:
#replaceChar function to replace space with hyphen
def replaceChar(string):
newString = ''
#Looping through each character of string
for a in string:
#if char is space, replace it with hyphen
if a == ' ':
newString += '-'
#else leave the character as it is
else:
newString += a
return newString
userInput = input("Enter a sentence: ")
#Calling the replaceChar function to replace space with hyphen
result = replaceChar(userInput)
#Printing the modified sentence
print("The new sentence is:",result)
OUTPUT:
Enter a sentence: Python has several built-in functions that allow us to work with strings.
The new sentence is: Python-has-several-built-in-functions-that-allow-us-to-work-with-strings.
Admissions Open for 2025-26