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

'''

                 reverseStr = ''
                 for i in range(len(str1)):
                     reverseStr = str1[i] + reverseStr
                 return reverseStr

             def palindrome(string):
                 '''
                 Objective : To check whether a string is a palindrome
                 Input Parameter : string
                 Return Value : 1 if the string is palindrome, 0 otherwise
                 '''



                 reverseString = reverseStr(string)
                 if reverseString == string:
                     return 1

                 else:
                     return 0


             myString = input("Enter a string: ")
             result = palindrome(myString)
             if result == 1:

                 print("Input string is a palindrome.")
             else:
                 print("Input string is not a palindrome.")
        Program 13

        Write a program that takes a user-provided string as input and then generates a new string where the case (uppercase
        to lowercase and vice versa) of each character in the original input is reversed, and finally, print the resulting string.
        Ans. def swapCase(string):

                 '''
                 Objective :  To convert the case of the characters of the string
                 Input Parameter : string
                 Return Value : newString – string

                 '''
                 newString = ''
                 for char in string:
                     if char.isalpha():
                         if char.islower():
                             newString += char.upper()

                         else:
                             newString += char.lower()

         428   Touchpad Computer Science-XI
   425   426   427   428   429   430   431   432   433   434   435