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

Sr. No.                        Command                                       Output
                   20    code1.isalnum()                                          False
                   21    code4.isalnum()                                          True
                   22    code5.isalnum()                                          False

                   23    code6.isalnum()                                          True
                   24    code1.isspace()                                          False
                   25    code7.isspace()                                          True
                   26    code1.startswith('stay')                                 False
                   27    code2.startswith('stay')                                 True
                   28    code4.endswith('99')                                     True
                   29    code5.endswith('9')                                      True
                   30    code7.endswith(' ')                                      True

                   31    code7.rfind('s')                                         -1
                   32    code2.rfind('s')                                         20
                   33    code1.index('S')                                         0
                   34    code5.index('s')                                         Error
                   35    code2.replace('stay','Be')                               'Be alert and Be safe'

                   36    code5.replace('9','0')                                   'Call@000'
                   37    code6.replace('z','#')                                   'Call999'
                   38    code2.split()                                            ['stay', 'alert', 'and', 'stay', 'safe']
                   39    code2.split('y')                                         ['sta', ' alert and sta', ' safe']
                   40    code5.split('@')                                         ['Call', '999']
                   41    code1.partition(' ')                                     ('Stay', ' ', 'Safe')
                   42    code5.partition('@')                                     ('Call', '@', '999')

                   43    '*' .join(['stay','safe','and','secure'])                'stay*safe*and*secure'
                   44    '#'.join([code9,code3])                                  'safetyfirst#STAY AWARE'
                   45    code7.join([code5,code6,code4])                          'Call@999  Call999  999999999'

            Program 33
            Write a program that accepts a string as input and displays the count of alphabets, digits, and special characters
            contained in it.

            Ans. def countCharacters(string):
                     '''
                      Objective : To calculate count of alphabets, digits and special characters
                      in a sring
                     Input Parameter : string

                     Return Value : alphabetCount, digitCount, specialCount – numeric values
                     '''
                     # Initialize counters for alphabets, digits, and special characters
                     alphabetCount = digitCount = specialCount = 0
                     # Iterate through each character in the input string



                                                                                                      Practical  443
   440   441   442   443   444   445   446   447   448   449   450