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

RecallnthatnanPythonnprogramnionanglobalnframeninnwhichnfunctononandnotatementonappearn(oeen ign8.4a).nWhennthen
        codeninnthenPythonnmoduleninterest.pynionexecuted,nPythonnencounteronthendefinitonnofnfunctonninterest()n
        (lineon1-11)n)innthenglobalnframenandnmakeonannotenofnit,naonohownninn iguren8.4a.n















                                 ign8.4a:nPythonnnoteonofnthendefinitonnofnthenfunctonninterest().
        ● nOnnexecutonnofnlineon22-n24,nPythonntakeonuoerninputonfornthenprincipalnamountn(p),nrate of interestn(r),n
           andntime periodn(t).
        ● nLetnuonaooumenp,nr,nandntntakenvalueon1000,n5,nandn2,nreopectvely.n
        ● nExecutonnofnlinen25nvalidateontheninputo.nStatementnassertnpaooeonthencontrolntonthenfollowingnotatementn(linen26)n
           onlynifnthenconditonnmentonedninnthenotatementnholdonTrue,notherwioe,nflagonannerror.

        ● nLinen26nionannaooignmentnotatement.nThenevaluatonnofnthenexpreooionnonnthenright-handnoidenofnthenaooignmentn
           operatornreoultoninnancallntonthenfunctonninterest().n

        ● nAonbefore,ninoteadnofnoayingnwencallnthenfunctonninterest(),nwencannoaynthatnweninvokenthenfunctonninterest().n
           Thuo,nthencontrolniontranoferredntonlinen1nofnProgramn8.3bnwherenthendefinitonnofnthenfunctonninterest()nbegino.
        ● nThenvalueon1000,n5,nandn2narenpaooednaoninputontonthenfunctonninterest()nandnarenaooignedntonthenformaln
           parameteron(aloonknownnaondummynparametero)nprincipal,nrate,nandntimen(oeen ign8.4b).
        Notenthatnancallntonthenfunctonncomprioeonthennamenofnthenfuncton,nfollowednbynanpairnofnparentheoeonthatnincludeon
        (optonally)nancomma-oeparatednoequencenofnargumento:
        function_name([comma_separated_sequence_of_arguments])
         urther,nnotenthatnthenargumentoninnthenfunctonncallnappearninnthenoamenorderninnwhichnformalnparameteronappearninn
        thenfunctonndefiniton.



























                               ign8.4b:nCallntonfuncton interest() withnparametero:n1000, 5, 2
        Lineon 2-9n inn then functonn interest()n aren forn documentatonn purpooe.n Executonn ofn linen 10n computeon
        simpleInterest.nNotenthatnthenreturnnvaluenreferonto simpleInterestn(oeen ign8.4c).

         190   Touchpad Computer Science-XI
   187   188   189   190   191   192   193   194   195   196   197