Page 44 - PYTHON-12
P. 44
33. A CSV file, ‘AnimalSurvey.csv’, contains the data of a survey. Each record of the file contains the following
data:
• Species (4)
• Habitat
• Population Count
• Protected Status (Yes/No)
For example, a sample record of the file may be:
[‘Panda’, ‘Forest’, 1864, ‘Yes’]
Write the following Python functions to perform the specified operations on this file:
(I) Read all the data from the file in the form of a list and display all those records for which the population
is more than 2000.
(II) Count the number of species with Protected Status marked as ‘Yes’.
34. Samarth is working as a Database Administrator in an ecommerce company and using EcommerceDB to
manage its inventory and customer orders. There are two tables: PRODUCTS and ORDERS. Help him extract
the following information by writing the desired SQL queries as mentioned below. (4)
Table: PRODUCTS
Product_ID Product_Name Category Price Stock
P7001 Wireless Mouse Electronics 1500 100
P7002 Gaming Keyboard Electronics 3500 50
P7003 Office Chair Furniture 7800 30
P7004 Laptop Bag Accessories 2000 150
Table: ORDERS
Order_ID Product_ID Customer_Name Order_Date Quantity Total_Amount
801 P7001 Samaira 2024-10-20 2 3000
802 P7002 Diviyansh 2024-11-02 1 3500
803 P7003 Mehak 2024-09-21 1 7800
804 P7004 Nimish 2024-08-09 3 6000
(I) To display the details of products in ‘Electronics’ category that are priced above 30.
(II) To display the total sales for each product (Quantity * Price).
(III) To reduce the stock of all products by 10.
(IV) (A) To display the names of customers who purchased more than one product of the same type.
OR
(B) To display the Cartesian Product of PRODUCTS and ORDERS tables.
35. SHOPDB database has a table, CUSTOMERS, with the following structure: (4)
Field Type
customerID int(11)
CustomerName varchar(50)
City varchar(30)
totalPurchases float
membership varchar(10)
Practice Paper A.7