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

toggleWord = ''
                  for indx in range(len(word)):
                      if indx % 2 == 0:
                          toggleWord += word[indx]
                      else:
                          toggleWord += word[indx].upper()
                  print("The new string is : ", toggleWord)




                                                      Assessment



            A.  Multiple Choice Questions
               1.  Which of the following operators is not compatible with strings?
                  a.  +                    b. *                   c. **                 d. in

               2.  Which of the following statements will return the last two characters of the string, message?
                  a.  message[0:2]         b. message[-1:2]       c. message[2:0]       d. message[-1:-3:-1]
               3.  Given a string, named, sentence, which of the following statements will return a list of words?

                  a.  sentence.split()
                  b.  sentence.partition()
                  c.  sentence.words()
                  d.  sentence.substr()
               4.  Consider the following code segment and choose the correct output that will be produced on its execution:
                  message1 = "Hello how are you?"
                  ch = '*'
                  message2 = ch.join(message1)
                  myList = message2.split()
                  print(myList[0],myList[-2],sep='#')
                  a.  H*e*l*l*o*#*a*r*e*
                  b.  Hello##are
                  c.  Hello******##are****
                  d.  Error
               5.  Which of the following functions removes all whitespace characters from the beginning and end of the string?
                  a.  lstrip()             b. rstrip()            c. allstrip()         d. strip()
               6.  Consider the following string
                     slogan = "One World One Future"
                  Which of the following pairs of statements will yield the same output?
                  a.  slogan[2:8] and slogan[-8:-3]
                  b.  slogan[:4] and slogan[10:13]
                  c.  slogan[-1:] and slogan[0:]
                  d.  slogan[4:10:2] and slogan[-12:-16:-2]
               7.  Consider the following code segment and select the correct output that will be produced on its execution:
                  fact = "Hardwork is the key to success"
                  fact.find("Key")
                  a.  -1                   b. 16                  c. -14                d. Error



                                                                                                       Strings   281
   278   279   280   281   282   283   284   285   286   287   288