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

newStr = newStr+message[i].upper()
                  elif message[i].isdigit():
                      str1 = eval(message[i])
                      newStr = newStr + str(str1)
                  else:
                      newStr = newStr + '#'


              print('Original string: ', message)
              print('New string: ', newStr)

         Ans:  Original string:  Hello123Hello?*$
              New string:  #ELLO123#ELLO###
           5.  What will be the output produced on the execution of the following code?
              import string
              startString = '#NaTO5*'
              finalString = ' '
              pos = 0
              value = 1
              while pos < len(startString):
                  if startString[pos] >= '0' and startString[pos] <= '9':
                      value = int(startString[pos])
                      value = value - 1
                      finalString = finalString+startString[value]
                  elif startString[pos].isupper():
                      if startString[pos] not in 'AEIOU':
                          finalString = finalString + '$'
                      else:
                          finalString = finalString + startString[pos + 1]
                  else:
                      finalString = finalString + '*'
                  pos = pos + 1
              print(finalString)
         Ans:  *$*$5O*
           6.  Consider the following string:
              quote = "#Books are friends"
              Find the string that the following calls to str methods will yield:
              (i)  quote.lower()
              (ii)  quote.upper()
              (iii)  quote.title()
              (iv)  quote.capitalize()
              (v)  quote.isupper()
              (vi)  quote.islower()
              (vii)  quote.isalpha()
              (viii) quote.isdigit()
              (ix)  quote.isspace()


         276   Touchpad Computer Science-XI
   273   274   275   276   277   278   279   280   281   282   283