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

print('New string:', obfuscate('Hello123?*$'))
                      print('Original string:', 'Hello123Hello?*$')
                      print('New string:', obfuscate('Hello123Hello?*$'))
                  Ans.  Original string:  Hello123?*$
                      New string:  #ELLO123###
                      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()
                      (x)  quote.startswith("#Book")
                      (xi)  quote.endswith("Friends")
                      (xii)  quote.replace('e','$')
                  Ans.  (i)  '#books are friends'
                      (ii)  '#BOOKS ARE FRIENDS'
                      (iii)  '#Books Are Friends'
                      (iv)  '#books are friends'

                                                                                                            Strings   357
   366   367   368   369   370   371   372   373   374   375   376