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

'''

                    if (n1 >= n1) and (n1 >= n3):
                        maximum = n1
                    elif (n2 >= n1) and (n2 >= n3):
                        maximum = n2
                    else:
                        maximum = n3

                    return maximum
               2.  Write a function max2(n1,n2)that finds the maximum of two numbers and then make use of the function max2(n1,n2)
                  to write the function max3(n1, n2, n3) to find the maximum of the numbers n1, n2, and n3.
             Ans.  def max2(n1, n2):
                     '''
                     Objective: To find maximum of two numbers
                     Input Parameters: n1, n2 - numeric values
                     Return Value: maximum of n1, n2 - numeric value
                     '''
                     '''
                     Approach:
                     Compare two numbers and return the maximum of two numbers.
                     '''

                     if n1 > n2:
                         return n1
                     else:
                         return n2
                 def max3(n1, n2, n3):
                     '''
                     Objective: To find maximum of three numbers
                     Input Parameters: n1, n2, n3 - numeric values
                     Return Value: maximum of n1, n2, n3 - numeric value
                     Approach: Find maximum of two numbers at a time
                     '''
                     return max2(max2(n1, n2), n3)
               3.  Write a program to find the number of four-digit palindrome numbers divisible by 11. You are not allowed to use a function
                  palindrome(string)that returns True if the input string is a palindrome and False otherwise.
             Ans.  def div11Palindromes():

                     '''
                     Objective: To find the number of four-digit palindrome divisible by 11
                     Input Parameter: None
                     Return Value: count of palindromes divisible by 11
                     '''
                     count = 0
                     start = 1001 #1001 is divisible by 11


                                                                                                      Modules    291
   288   289   290   291   292   293   294   295   296   297   298