Page 448 - Computer Science Class 11 With Functions
P. 448
print("6. Convert to title case")
print("7. Exit")
choice = input("Enter your choice (1/2/3/4/5/6/7): ")
if choice == '1':
length = stringLength(string)
print(f"Length of the string: {length}")
elif choice == '2':
mCount = mCountOccurrence(string)
print(f"Number of 'm' occurrences: {mCount}")
elif choice == '3':
digitCount = countDigits(string)
print(f"Number of digits: {digitCount}")
elif choice == '4':
modifiedString = replaceSpaces(string)
print(f"String with spaces replaced by '*': {modifiedString}")
elif choice == '5':
lowercaseString = convertToLowercase(string)
print(f"String converted to lowercase: {lowercaseString}")
elif choice == '6':
titleCaseString = convertToTitleCase(string)
print(f"String converted to title case: {titleCaseString}")
elif choice == '7':
print("Exiting the program.")
break
else:
print("Invalid choice. Please select a valid option.")
Program 35
Write a program that accepts two strings and checks whether the second string is a substring (forms part) of the
first string. If yes, the program should display the starting index that marks the beginning of the second string;
otherwise, it should display 'Substring DOES NOT exist.'
Ans. def findSubstring(string1, string2):
'''
Objective : To check whether a string is substring of another and tell its
index
Input Parameter : string1,string2 - string
Return Value : index – numeric value, string
'''
index = string1.find(string2)
if index != -1:
return index
446 Touchpad Computer Science-XI

