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

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
              05 '''
              06 #Approach: First write a function to compute student's grade
              07 def grade(percentage):
              08     '''
              09     Objective: To compute a student's grade, base d on his/her percentage
              10     Input: percentage: percentage of marks obtained by t he student
              11     Return Value: grade: A, B, C, D, F
              12     cutoffs 75, 60, 50, 33, respectively
              13     '''
              14     cutOffA = 75
              15     cutOffB = 60
              16     cutOffC = 50
              17     cutOffD = 33
              18     if percentage >= cutOffA:
              19         return 'A'
              20     elif percentage >= cutOffB:
              21         return 'B'
              22     elif percentage >= cutOffC:
              23         return 'C'
              24     elif percentage >= cutOffD:
              25         return 'D'
              26     else :
              27         return 'F'
              28 percentage = int(input("Enter student's percentage: "))
              29 yourGrade = grade(percentage)
              30 print('Your grade is : ', yourGrade)
            InlShtltxnepatlgivtnlnbovt,liflpercentage  itl54,ltnchloflShtllShtlconditonnaltxprtttiontlpercentage  >=
            cutOffA,  nnd  percentage  >=  cutOffB  yitadtl(onltvnaunton) False,  buSlShtlconditonnaltxprtttion
            percentage >= cutOffC yitadtl(onltvnaunton) True, to ShtltSnStetnS:

                return 'C'
            itltxtcuStdlnndlShtlvnautloflyourGrade itlttSltqunalSol'C'.lFinnaay,lonlShtltxtcutonloflShtltSnStetnS:
            l   print('Your grade is', yourGrade)
            PyShonlinStrprtStrllouSpuStlShtletttngt:l

            Your grade is C
             nepatlOuSpuS:
             >>> Enter student's percentage:  54
                 Your grade is C
            Program 9.7 WriStlnlprogrnelShnSlchtcktlwhtShtrlnlnuebtrlitlpotitvt,lntgntvt,lorlztro,lnndlditpanytlnnlnpproprinSt
            etttngt.

            Solution:

              01 #Objective: To check whether a number is positive, negative or zero
              02 num = int(input("Enter a number : "))
              03 if num > 0:
              04     print("POSITIVE")
              05 elif num < 0:
              06     print("NEGATIVE")
              07 else:
              08     print("Number is ZERO")



                                                                                          Conditonnal SnStetnSt  215
   212   213   214   215   216   217   218   219   220   221   222