Page 509 - Computer Science V2.0 Class 11
P. 509

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
                         '''
                         reverseStr = ''

                         for i in range(len(str1)):
                             reverseStr = str1[i] + reverseStr
                         return reverseStr
                     def palindrome(string):
                         '''
                         Objective : To check whether a string is a palindrome

                         Input Parameter : string
                         Return Value : 1 if the string is palindrome, 0 otherwise
                         '''



                         reverseString = reverseStr(string)
                         if reverseString == string:
                             return 1
                         else:
                             return 0



                     myString = input("Enter a string: ")
                     result = palindrome(myString)

                                                                                                           Practical  495
   504   505   506   507   508   509   510   511   512   513   514