Page 11 - PYTHON-12
P. 11

Ans.  (a)  (i)  Select * from STUDENT order by Name;
                    (ii)  Select avg(Marks) from STUDENT where city = "Delhi";
                   (iii)  Select * from STUDENT where Name like '%a';
                    (iv)  Select count(*) from STUDENT where Class = 'XI' or Class = 'XII';
                (b)  (i)
                         RollNo    Name     Class       DOB        Gender    City     Marks
                        3        Sonal      XI     1994-05-06     F        Delhi    400
                        4        Trisla     XII    1995-08-08     F        Mumbai   450
                        7        Neha       X      1995-12-08     F        Moscow   377

                    (ii)
                         RollNo       DOB          City
                        6        1994-12-12     Dubai

                   (iii)
                        Min(Marks)
                        250
                    (iv)
                          Name      Marks
                        Nanda        551
                        Marisla      250

            33.  Write user-defined functions to perform read and write operations on to a ‘teacher.csv’ file having fields
               TeacherID, Name, Subject and Experience (in years).                                         (4)

           Ans.  import csv
               row=['2101','Amrita Rana', 'Science','15']
               def readcsv():
                    with open("teacher.csv",'r') as f:
                    data=csv.reader(f)
                    for row in data:
                       print(row)
               def writecsv():
                    with open("teacher.csv",'w',newline='') as fobj:
                    csv_w=csv.writer(fobj,delimiter=',')
                    csv_w.writerow(row)
               print("Press 1 to read data and Press 2 to write data")
               a=int(input())
               if a==1:
                  readcsv()
               elif a==2:
                  writecsv()
               else:
                  print("Invalid value")
            34.  Dhriti works in Prilknot Pvt. Ltd. She needs to access some information from SALESMAN and CUSTOMER tables.
               Help her extract the following information by writing the desired SQL queries as mentioned below.   (4)
                                         Table: SALESMAN
                  Salesman_id         Name              City         Commission
                5001             Jai Chauhan      New York              0.15
                5002             Neil Mahajan     Paris                 0.13
                5005             Priyank Chawla   London                0.11
                5006             Prerna Malhotra  Paris                 0.14
                5007             Jyoti Singh      Rome                  0.13
                5003             Aaren Kumar      San Jose              0.12

          A.42                                                           Computer Science with Python–XII
   6   7   8   9   10   11   12   13   14   15   16