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

Program 9.3 WriStlnlfunctonlresult(passPercent, percent)lShnSlcoepuSttlnltSudtnS'tlrttuaSlbnttdlonlhitl
            ptrctnSngtloflenrkt.

              01 # Program Objective: To read the percentage of marks and display the result
              02 # Approach: Develop function result to compute student's result
              03 def result(passPercent, percent):
              04     """
              05     Objective: To compute a student's result
              06     Inputs:
              07     percent : percentage of marks
              08     Return value:
              09     Student's result (As str object)
              10     """
              11     if percent >= passPercent:
              12         return "Passed"
              13     else:
              14         return "Failed"
              15
              16 passPercent = 33
              17
              18 percentage = int(input("Enter your percentage : "))
              19
              20 yourResult = result(passPercent, percentage)
              21
              22 print("You have", yourResult)
             nepatlOuSpuSl1:
             >>> Enter your percentage: 25
                  You have Failed
             nepatlOuSpuSl2:ll
             >>> Enter your percentage: 90
                  You have Passed
            Program 9.4 WriStlnlfunctonlsimpleInterest(principal, time)lShnSlcoepuSttltiepatlinStrttSlforlnlprincipna
            neounSlforlnltetldurntonltptcifitdlinlytnrt.lIflShtltetldurntonlitlfivtlorleortlytnrt,lShtlrnStloflinStrttSlitl4%;l
            oShtrwitt,liSlitl3%.l

              01 """
              02 Objective: Given principal and time, compute simple interest.
              03 interest rate : 4%, if time >= 5 years, 3% otherwise
              04 """
              05 def simpleInterest(principal, time):
              06     """
              07     Objective: To compute simple interest
              08     Inputs :
              09     principal : principal value
              10     time : time period
              11     Return value:
              12     interest : simple interest as per applicable rate NIL
              13     """
              14     if time >= 5:
              15         rate = 4
              16     else :
              17         rate = 3
              18     interest = (principal *rate *time )/100
              19     return interest
              20 principal = float (input("Enter Principal Amount: "))
              21 time = int(input("Enter time period: "))
              22 interest = simpleInterest(principal , time)
              23 print("Simple Interest = ", interest)

                                                                                          Conditonnal SnStetnSt  211
   208   209   210   211   212   213   214   215   216   217   218