Page 121 - Information_Practice_Fliipbook_Class11
P. 121

Nested if statement

            NtxS,latSlutlwriStlnlprogrnel(Progrnel5.5)lShnSlncctpStlfroelnluttrlShtlptrctnSngtloflenrktlobSnintdlbylnltSudtnSlnndl
            ditpanytlnlattttrlgrndt,lbnttdlonlShtlptrctnSngt.lThtlprogrnelwiaalcoepuStlShtltSudtnS'tlgrndtlbnttdlonlShtltSudtnS'tl
            ptrctnSngtlnndlShtlcuS-offlenrktltptcifitdlforlShnSlgrndt.lISlonaylnttdtlSolchtcklinlttqutnctlwhtShtrlnltSudtnS'tl
            ptrctnSngtltxcttdtlorltqunatlShtlptrctnSngtlrtquirtdlforlShtlgrndttlA,lB,lC,land D.lIflnltSudtnSlhntltcortdlnl
            ptrctnSngtloflenrktlShnSldottlnoSlqunaifylhie/htrlforltvtnl'D'lgrndt,lht/thtlitlnwnrdtdlnnl'F'lgrndt,lindicntnglShnSl
            ShtltSudtnSlhntlfniatd.lNoStlShnSlShtlhighlatvtaloflntttnglenkttlShtlprogrneltoetwhnSlhnrdlSolrtnd.

            NoStlShnSlinlShtlprogrne,lnnlifltSnStetnSlitltncaottdlwiShinlnnoShtrlifltSnStetnS.lWhtnlnltSnStetnSltncaotttl
            nnoShtrltSnStetnS,lShtltncaottdltSnStetnSlitlcnaatdlnlnttStdltSnStetnS.

            Program  5.5  WriStl nl progrnel ShnSl coepuSttl Shtl tSudtnS'tl grndtl bnttdl onl Shtl tSudtnS'tl ptrctnSngtl nndl Sht
            cuS-offlenrktltptcifitdlforlShnSlgrndt.

                                                    Percentage      Grade
                                                       >=75              A
                                                       >=60              B
                                                       >=50              C

                                                       >=33              D
                                                       <l33              F
            Solution:
              01 '''
              02 Objective: To display a student's grade, based on his/her percentage
              03 User input: percentage of marks obtained by the student
              04 Output: Student's grade: A, B, C, D, or F cutoffs 75, 60, 50, 33, respectively
              05 '''
              06
              07 percentage = int(input("Enter student's percentage: "))
              08
              09 assert percentage >=0 and percentage <=100
              10
              11 cutOffA = 75
              12 cutOffB = 60
              13 cutOffC = 50
              14 cutOffD = 33
              15
              16 if percentage >= cutOffA:
              17     grade = 'A'
              18 else:
              19     if percentage >= cutOffB:
              20         grade = 'B'
              21     else:
              22         if percentage >= cutOffC:
              23             grade = 'C'
              24         else:
              25             if percentage >= cutOffD:
              26                 grade = 'D'
              27             else:
              28                 grade = 'F'
              29
              30 print('Your grade is', grade)
             nepatlOuSpuSl1:

             >>> Enter student's percentage:  89
                 Your grade is A


                                                                                          Conditonnal SnStetnSt  107
   116   117   118   119   120   121   122   123   124   125   126