Page 62 - PYTHON-11
P. 62

25.  What will be the output of the following code?                                          (2)
                     import statistics
                     data = [110, 250, 380, 430, 560]
                     print(statistics.mean(data))
                Ans.  346
                 26.  Explain any two functions of math module.                                               (2)
                Ans.  Two functions of math module are as follows:
                      (a)  pow(x, y): It returns the value of x , where x and y are numeric expressions.
                                                       y
                         For example, print(math.pow(3,2)) gives output 9.0.
                      (b)  sqrt(x): It returns the square root of x.
                         For example, print(math.sqrt(100)) gives output 10.0.
                 27.  (a)    (i)  Explain break and continue statements in Python.                            (2)
                                                               OR
                          (ii)  What is the purpose of pass statement in Python?
                      (b)    (i)  Write a Python statement to check whether an inputted number is positive or negative.
                                                               OR
                          (ii)   Write a Python conditional statement to check whether the entered number is divisible by 5 or not.
                Ans.  (a)  (i)  break statement terminates the current loop, i.e., the loop in which it appears, and resumes the
                             execution at the next statement immediately after the end of that loop. If  break statement
                             is inside a nested loop (loop inside another loop),  break will terminate the innermost loop.
                             However, when continue statement is encountered, the control jumps to the beginning of the
                             loop for next iteration, thus skipping the execution of statements inside the body of the loop for
                             the current iteration. The loop condition is checked to see if the loop should continue further
                             or terminate. If the condition of the loop is still true, the loop is entered again; otherwise, the
                             control is transferred to the statement immediately following the loop.
                                                               OR
                         (ii)  pass statement is a NULL operation, i.e., nothing happens when it executes. It is used when a
                             statement is required syntactically but we do not want any command or code to execute. It
                             results in no operation.
                      (b)  (i)  if num>=0:
                              print("num is positive")
                            else:
                              print("num is negative")
                                                               OR
                         (ii)  if num%5==0:
                               print(" num is divisible by 5")
                            else:
                               print("num is not divisible by 5")
                 28.  (a)  Identify the following string built-in functions.                                  (2)
                          (i)  This function returns the string with the first letter of every word in the string in uppercase
                             and the rest in lowercase.
                         (ii)  This function is used to split the given string using the specified separator and returns a tuple with
                             three parts.
                                                               OR
                      (b)  Identify the following list built-in methods:
                          (i)  This method adds one list at the end of another list.
                         (ii)  This method removes an element from specified index and also returns the removed element.
                Ans.  (a)  (i)  title()
                         (ii)  partition(separator)
                                                               OR
                      (b)  (i)  extend()
                         (ii)  pop()



                                                          M.11
   57   58   59   60   61   62   63   64   65   66   67