Page 429 - Computer Science Class 11 With Functions
P. 429

Program 11

            Write a program that accepts a string as input from the user and prints the count of vowels, consonants, uppercase,
            and lowercase characters.
            Ans. def countChar(dataString):

                     '''
                      Objective : To display the count of vowels, consonants, upper case, and lower
                      case characters
                     Input Parameters : dataString - string
                      Return Value : Tuple with count of vowels, consonants, upper case, and lower
                      case characters
                     '''
                     cntV = 0
                     cntC = 0
                     cntU = 0

                     cntL = 0
                     for ch in dataString:
                         if ch.isalpha():
                             if ch in "aeiouAEIOU" :

                                 cntV += 1
                             else:
                                 cntC += 1
                             if ch.islower():
                                 cntL += 1
                             else:

                                 cntU += 1
                     return (cntV,cntC,cntU,cntL)

                 dataString = input("Enter a string : ")

                 countTuple = countChar(dataString)
                 print("The number of vowels are : ", countTuple[0])
                 print("The number of consonants are : ", countTuple[1])
                 print("The number of uppercase characters are : ", countTuple[2])
                 print("The number of lowercase characters are : ", countTuple[3])
            Program 12

            Write a program that accepts a string as input from the user and checks whether the string is a palindrome or not.

            Ans. def reverseStr(str1):
                     '''
                     Objective: To reverse a string
                     Input Parameter: str1 - string

                     Return Value: reverseStr - reverse of str1


                                                                                                      Practical  427
   424   425   426   427   428   429   430   431   432   433   434