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

Case-based Questions


                    1.  Onkar had created a program to accept time in seconds and then display it in minutes and seconds. Today, his teacher
                      explained the concept of Functions in class and also gave him the task of creating the same program using user-defined
                      functions. The program will accept the value of time in seconds passed as an argument to the function called convertTime(t).
                      The function will then display time in minutes and seconds.

                  Ans.  def convertTime(seconds):
                          '''
                         Objective: To convert seconds to minutes and seconds
                          Input perimeters: seconds – numeric value
                          Return Value: minutes,   seconds - numeric value

                          '''
                          minutes = seconds//60
                          seconds = seconds%60
                          return minutes,   seconds
                      tSec = int(input('Enter the time in seconds :  '))
                      minutes,   seconds = convertTime(tSec)

                      print('The time is ',   minutes,   'minutes',   seconds,   '  seconds')
                    2.  Sumedha wants to create a function that takes height in feet and inches as arguments and returns the height in centimeters.
                      Help her write the function and then call the function to view the output.
                  Ans.  def convertHeight(feet, inches):

                          '''
                          Objective: To compute height in cms
                          Input Parameters: feet,   inches – numeric values
                          Return Value: cms- float value
                          '''
                          cms = feet * 30.48 + inches * 2.54
                          return round(cms,  2) #rounded to 2 decimal places

                      feet = float(input('Enter height in feet : '))
                      inches = float(input('Enter inches: '))
                      heightInCms = convertHeight(feet, inches)
                      print('The height in cms is: ',  heightInCms)



                                                          Assessment



                 A.  Multiple Choice Questions.
                    1.  Which of the following keywords is used to start a function definition?
                      a.  DEF                   b. RETURN             c. return              d. def

                    2.  Which of the following is not included during a function call?
                      a.  Function name         b. Pair of parenthesis   c. colon(:)         d. Argument(s)

                    3.  Which of the following is NOT a built-in function?
                      a.  input()               b. max()              c. sin()               d. eval()

                                                                                             Introduction to Functions  213
   222   223   224   225   226   227   228   229   230   231   232