Page 25 - PYTHON-12
P. 25

Ans.  (I)  import csv
                       def read_display():
                               high_score_students = []
                               try:
                                    with open("StudentGrades.csv", 'r') as file:
                                          reader = csv.reader(file)
                                          next(reader)
                                          for row in reader:
                                                student_name = row[0]
                                                subject = row[1]
                                                grade = row[2]
                                                percentage_score = float(row[3])
                                                if percentage_score > 85:
                                                     high_score_students.append(row)
                                    print("Students who scored more than 85%:")
                                    for student in high_score_students:
                                          print("Student        Name:       ",student[0],        "Subject:",
                                          student[1], "Grade:", student[2], "Percentage Score:",
                                          student[3])
                               except FileNotFoundError:
                                    print("Error: The file StudentGrades.csv was not found.")
                   (II)  def count_records():
                               record_count = 0
                               try:
                                    with open("StudentGrades.csv", 'r') as file:
                                          reader = csv.reader(file)
                                          next(reader)
                                          for row in reader:
                                                record_count += 1
                                    print("Total number of records in the file:",record_count)
                               except FileNotFoundError:
                                    print("Error: The file StudentGrades.csv was not found.")
                34.  Manish has been assigned the task of managing the database of Nirvana Group of Hotels. He needs to access
                   some information from GUESTS and BOOKINGS tables for a survey analysis. Help him extract the following
                   information by writing the desired SQL queries as mentioned below.                       (4)
                                                        Table: GUESTS
                      Guest_ID       First_Name     Last_Name     Check_in_Date    Room_Type       Duration

                    3001           Neena          Jain            2024-10-20     Suite          3
                    3002           Mukesh         Gupta           2024-09-18     Deluxe         2
                    3003           Raman          Chugh           2024-08-15     Standard       1
                    3004           Namrata        Malhotra        2024-11-02     Suite          4
                                                       Table: BOOKINGS

                       Booking_ID         Guest_ID          Room_No          Room_Charges      Total_Charges
                    4001              3001              101                15000             45000
                    4002              3002              409                10000             20000
                    2003              3003              310                6500              6500
                    4004              3004              207                16500             66000



                                                                                Model Test Paper (Solved)  A.11
   20   21   22   23   24   25   26   27   28   29   30