Page 285 - Computer Science Class 11 Without Functions
P. 285

iMessage = "Taking Off"
                  iMessage[-1] = 'n'
               3.  What will be the output on execution of the following statements:
                  (i)  >>> msg1 = 'Welcome'
                     >>> msg2 = 'User'
                     >>> msg1 + msg2
                     >>> msg1 * 3
                     >>> print(len(msg1))
                  (ii)  >>> numApples = '34'
                     >>> numOranges = '12'
                     >>> print('I have', numApples + numOranges, 'fruits')
                  (iii)  >>> string ='I love Python.'
                     >>> string.split()
                     >>> string.partition(' ')
               4.  Apply appropriate functions to the string  poem to achieve the following:
                  poem = 'We live in a beautiful world. Full of beauty, majesty, and wonder. Like a beautiful
                  sea of diamonds and pearls.'
                  (i)  FInd the number of characters in the string poem.
                  (ii)  Split the string into substrings on the basis of the delimiter period.
                  (iii)  Split the string into substrings on the basis of delimiter - and.
                  (iv)  Find the number of occurrences of the word -beautiful.

                  (v)  Find  the index of the first occurrence of the word -beautiful.
                  (vi)  Find the index of the first occurrence of the word -beautiful from the right end of the string.
               5.  Examine the following statement and rectify the error in the following piece of code:
                  >>> msg = 'Try to be a rainbow in someone else's cloud.'
                      SyntaxError: unterminated string literal (detected at line 1)
               6.  Consider the string given below:
                  Message = "Beware of dog no 2"
                  Give the output that will be produced on the execution of each of the following statements:

                  (i)  print(message[3:8])
                  (ii)  print(message[5:])
                  (iii)  print(message[-4:])
                  (iv)  print(message.endswith("2"))
                  (v)  print(message[:4]+message[4:])
                  (vi)  print(message.isalpha())
                  (vii)  print(message[::-3])
                  (viii) print(message[-4:-14])
                  (ix)  print(message[-2:-14:-1])
                  (x)  print(message.split())
               7.  Give the output that will be produced on the execution of each of the following code segments:
                  (i)  >>> message=" All IS WEll"
                    >>> message.find('Is')
                  (ii) str1="SunDay#1"
                    str2=""
                    k=0


                                                                                                       Strings   283
   280   281   282   283   284   285   286   287   288   289   290