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

03     Objective: To find maximum of three numbers
              04     Inputs:
              05     num1, num2, num3 : Numeric values'''
              06     if num1 < num2:
              07         if num2 < num3:
              08             return num3
              09         else:
              10             return num2
              11     else:
              12         if num1 < num3:
              13             return num3
              14         else:
              15             return num1
              16 n1 = int(input('Enter first number :'))
              17 n2 = int(input('Enter second number :'))
              18 n3 = int(input('Enter third number :'))
              19 print('Maximum of ', n1, n2, n3, ':', max3(n1, n2, n3))
            OuSpuS:
             >>> Enter first number :9
             >>> Enter second number :4
             >>> Enter third number :10
                 Maximum of 9 4 10 : 10
            MnxieueloflThrttlNuebtrtl(RtvitiStd):lNoStlShnSlShtlnbovtltoautonlSolfindinglShtlanrgttSloflShrttlnuebtrtlitl
            toetwhnSlconfuting.lWtlcnnltiepaifylShtlnbovtlcodtltubtSnntnaayliflwtlfirtSlwriStlnlfunctonlSolfindlShtlenxieuelofl
            nlpnirloflnuebtrt,lntliaautSrnStdlinlProgrnel9.12:l

            Program 9.12 WriStlnlfunctonlmax2(n1,n2)lShnSlfindtlShtlenxieueloflSwolnuebtrtlnndlShtnlenktluttloflSht
            functonlmax2(n1,n2) SolwriStlShtlfunctonlmax3(n1, n2, n3)lSolfindlShtlenxieueloflShtlnuebtrtln1,ln2,lnndln3.
              01 def max2(num1, num2):
              02     '''
              03     Objective: To find maximum of two numbers
              04     Inputs :
              05     num1, num2: Numeric values
              06     Return value: Maximum of num1, num2
              07     '''
              08     if num1 < num2:
              09         return num2
              10     else:
              11         return num1
              12
              13 def max3(num1, num2, num3):
              14     '''
              15     Objective: To find maximum of three numbers
              16     Inputs:
              17     num1, num2, num3 : Numeric values
              18     Return value: Maximum of num1, num2, num3
              19     '''
              20
              21     temp = max2(num1, num2)
              22     return max2(temp, num3)
              23
              24 n1 = int(input('Enter first number :'))
              25 n2 = int(input('Enter second number : '))
              26 n3 = int(input('Enter third number : '))
              27 print('Maximum of', n1, n2, n3, ':', max3(n1, n2, n3))




                                                                                          Conditonnal SnStetnSt  219
   216   217   218   219   220   221   222   223   224   225   226