Page 9 - PYTHON-12
P. 9

Section C

            26.  Write a function SetArray(ARR) in Python, which accepts a list Arr of numbers. The function should shift
               all the negative values to left and all the positive values to right.                       (3)
                Sample Input Data of the list Arr= [ –2, 3, –1, 4, –5, 7, –9, 6]
               Output:

               Arr = [-2, -1, -5,-9, 3, 4, 7, 6]
           Ans.  def SetArray(ARR):
                  newArr=[]
                   for x in ARR:
                    if x <0:
                     newArr.append(x)
                   for x in ARR:
                    if x>0:
                     newArr.append(x)
                  return newArr
               Arr=[–2, 3, –1, 4, –5, 7, –9, 6]
               result=SetArray(Arr)
               print(result)
            27.  Write a SQL statement to create the following table HOSPITAL.                             (3)

                                            Table: HOSPITAL
                 PNo      Name        Age     Department   DateofAdm    Charges    Sex
                  1    Sandeep         65    Surgery      1998-02-23      300      M
                  2    Ravina          24    Orthopaedic  1998-01-01      200       F
                  3    Karan           45    Orthopaedic  1998-02-19      200      M
                  4    Tarun           12    Surgery      1998-01-01      300      M
                  5    Zubin           36    ENT          1998-01-12      250      M
                  6    Ketaki          16    ENT          1998-02-24      300       F
                  7    Ankita          29    Cardiology   1998-02-20      800       F
                  8    Zareena         45    Gynaecology 1998-02-22       300       F
                  9    Kush            19    Cardiology   1998-01-13      800      M
                  10   Shaily          31    Medicine     1998-02-19      400      M

               Note: PNo is the primary key in the above table.
                         Table: HOD
                Department     HOD_name
                Surgery        Rajesh Jain
                Cardiology     K.K. Arora
                Medicine       Ishan Arora
                Gynaecology    Shruti Bhatia
                Orthopaedic    Ram Khosla
                ENT            Meena Kumar
                Write SQL commands for the statements (a) to (c) on the basis of the table HOSPITAL:
                (a)  To display the name of female patients admitted in Orthopaedic or ENT department.
                (b)  To count and display the no. of patients with more than 35 years of age.
                (c)  To display the patients who are admitted in the hospital and are treated by any HOD.

           Ans.  (a)  SELECT Name FROM Hospital
                   WHERE Sex='F' AND Department IN ('Orthopaedic','ENT');

          A.34                                                                     Computer Science with Python–XII
   4   5   6   7   8   9   10   11   12   13   14