Page 447 - Computer Science Class 11 With Functions
P. 447
def countDigits(string):
'''
Objective : To count the number of digits in the string
Input Parameter : string
Return Value : sum – numeric value
'''
return sum(1 for char in string if char.isdigit())
def replaceSpaces(string):
'''
Objective : To replace spaces in string with '*'
Input Parameter : string
Return Value : string
'''
return string.replace(' ', '*')
def convertToLowercase(string):
'''
Objective : To convert uppercase letters to lowercase
Input Parameter : string
Return Value : string
'''
return string.lower()
def convertToTitleCase(s):
'''
Objective : To convert string to title case
Input Parameter : string
Return Value : string
'''
return string.title()
string = input("Enter a string: ")
while True:
print("\nMenu:")
print("1. Length of the string")
print("2. Number of occurrences of 'm'")
print("3. Number of digits")
print("4. Replace spaces with '*'")
print("5. Convert to lowercase")
Practical 445

