Page 274 - Computer Science V2.0 Class 11
P. 274

Program 10.3 Write a function result(passPercent, percent) that computes a student's result based on his
               percentage of marks.
                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)
              Sample Output 1:

               >>> Enter your percentage: 25
                    You have Failed
              Sample Output 2:

               >>> Enter your percentage: 90
                    You have Passed
               Program 10.4 Write a function simpleInterest(principal, time) that computes simple interest for a principal
               amount for a time duration specified in years. If the time duration is five or more years, the rate of interest is 4%;
               otherwise, it is 3%.
                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)
               260   Touchpad Computer Science (Ver. 2.0)-XI
   269   270   271   272   273   274   275   276   277   278   279