26. Consider the following records in Cars table and answer the given questions:
| CarID |
Make |
Model |
Year |
Color |
Price |
| 101 |
Toyota |
Camry |
2022 |
Blue |
25000.00 |
| 102 |
Honda |
Civic |
2021 |
Black |
22000.00 |
| 103 |
Ford |
Mustang |
2023 |
Brown |
35000.00 |
| 104 |
Chevrolet |
Equinox |
2022 |
White |
28000.00 |
| 105 |
BMW |
X5 |
2023 |
Blue |
45000.00 |
| 106 |
Volkswagen |
Golf |
2021 |
Black |
20000.00 |
a. Write SQL query that will give the output as
Blu
Bla
Bro
Blu
Ans: SELECT LEFT(COLOR, 3) FROM Cars WHERE COLOR='Blue' OR COLOR='Black' OR COLOR='Brown';
b. Write command for the following
To change the colo r of Model with code as 103 to Green
Ans: UPDATE Cars SET Color = 'Green' WHERE CarID = 103;
c. How many tuples are present in the 'Cars' table?
Also identify the most suitable column of the cars table to mark as primary key column.
Ans: Number of tuples: 6
Primary key column: CarID
OR
a. SELECT Make, Model FROM Cars WHERE Price 30000.00;
Ans:
| Make |
Model |
| Ford |
Mustang |
| BMW |
X5 |
b. SELECT COUNT(*) AS TotalCars FROM Cars WHERE Year 2022;
Ans:
c. SELECT CarID, Make, Model FROM Cars where price<22000;
Ans:
| CarID |
Make |
Model |
| 106 |
Volkswagon |
Golf |
27. Complete the given Python code to get the required output as "California":
import ____________ as pd
data = {'Yosemite': 'California', 'Yellowstone': 'Wyoming', 'Glacier': 'Montana', 'Rocky Mountain': 'Colorado'}
national_parks = pd.Series(__________)
print(national_parks____________)
Ans:
import pandas as pd
data = {'Yosemite': 'California', 'Yellowstone': 'Wyoming', 'Glacier': 'Montana', 'Rocky Mountain': 'Colorado'}
national_parks = pd.Series(data)
print(national_parks['Yosemite'])
28. Suppose you already have "Nutrients" table in the "FOOD" database, as described below:
Table Name: Nutrients
Column Name: Food_Item (VARCHAR)
Column Name: Calorie (INT)
Write SQL statements to perform the following tasks:
i. Add a new column named “Plan_Start_Date (Date) to the "Nutrients" table.
Ans: ALTER TABLE Nutrients ADD Plan_Start_Date DATE;
ii. Modify the "Calorie" column to change its data type to Float.
Ans: ALTER TABLE Nutrients MODIFY Calorie FLOAT;
29. Imagine a scenario where an individual, Alex, is concerned about his online privacy. Alex has a social media presence and frequently posts updates, photos, and comments on various platforms. Additionally, Alex frequently uses mobile apps and visits websites for shopping and information.
a. Explain the concept of an active digital footprint, providing examples from Alex's online activities.
Ans: Active Digital Footprint: Alex's active digital footprint includes actions like posting photos and comments on social media platforms, making his intentional online activities visible to others.
b. Describe the concept of a passive digital footprint and provide examples of how it is generated in Alex's online interactions.
Ans: Passive Digital Footprint: Alex's passive digital footprint is created when websites and mobile apps collect data about his browsing habits and preferences without his direct input, often for purposes like targeted advertising.
c. Discuss the implications of both active and passive digital footprints for Alex's online privacy and security.
Ans: Implications of both active and passive digital footprints for Alex's online privacy and security: Alex's active digital footprint may expose him to privacy risks if he shares sensitive information publicly. His passive digital footprint, when mishandled, can lead to data privacy concerns and potentially put his personal information at risk, emphasising the need for cautious online behaviour and data protection measures.
OR
With reference to 3R’s, describe three essential approaches to manage electronic waste. Also, provide practical examples of how individuals can actively participate in each approach.
Ans: (i) Reduce: Individuals can minimise e-waste by making mindful purchasing decisions, such as buying longer-lasting electronic devices and only acquiring what is genuinely needed. For example, opting for modular smartphones with replaceable components can extend the lifespan of the device.
(ii) Reuse: Encouraging the reuse of electronic devices involves selling, donating, or trading-in old gadgets. For instance, individuals can refurbish and sell their old laptops to extend their use.
(iii) Recycle: To recycle e-waste responsibly, individuals can participate in e-waste recycling programs or drop-off centers. For instance, recycling old cell phones at designated collection points prevents them from ending up in landfills.
30. Consider the given DataFrame 'Employees':
| Name |
Employee_ID |
Department |
| Alice |
EMP001 |
HR |
| Bob |
EMP002 |
Sales |
| Carol |
EMP003 |
IT |
| David |
EMP004 |
Marketing |
Write suitable Python statements for the following operations:
i) Add a column called 'Salary' with the following data:
[55000, 60000, 65000, 58000]
Ans: Add a column 'Salary'
df['Salary'] = [55000, 60000, 65000, 58000]
ii) Include a new employee named 'Eve' with Employee_ID 'EMP005', working in the 'Finance' department, and a salary of 62000.
Ans: Include a new employee named 'Eve' with Employee_ID 'EMP005', working in the 'Finance' department, and a salary of 62000.
Employees.loc[4] = ['Eve', 'EMP005', 'Finance', 62000]
iii) Change the name of the 'Employee_ID column to 'ID'.
SECTION D
31. Imagine you are assigned a task to manage the inventory of an online store. The store uses an SQL database to track product information in a table named 'Products.' The 'Products' table has columns for 'ProductID' (Primary Key), 'ProductName', 'Category', 'QuantityInStock', and 'PricePerUnit.'
The following scenarios represent different inventory management tasks:
i) Restocking: Due to a recent sale, the 'QuantityInStock' of a product with 'ProductID' 101, named "Laptop," needs to be increased by 10 units.
Ans: UPDATE Products SET QuantityInStock = QuantityInStock + 10 WHERE ProductID = 101;
ii) Product Availability Check: You need to check the availability of a product named "Wireless Mouse" in the 'Electronics' category.
Ans: SELECT * FROM Products WHERE ProductName = 'Wireless Mouse' AND Category = 'Electronics';
iii) Product Update: The price of all products in the Electronics category should be increased by 5% to account for market changes.
Ans: UPDATE Products SET PricePerUnit = PricePerUnit * 1.05 WHERE Category = 'Electronics';
iv) Out of Stock: Identify and list the products that are currently out of stock (QuantityInStock is 0).
For each scenario, provide the SQL statements to perform the necessary action.
Ans: SELECT ProductName FROM Products WHERE QuantityInStock = 0;
32. Wizbiz Corporation is recording the quarterly sales data of its three products through different departments. The data is as follows:
|
Qtr1 |
Qtr2 |
Qtr3 |
Qtr4 |
| Product1 |
3500 |
4200 |
4800 |
5100 |
| Product2 |
2800 |
3100 |
3600 |
3900 |
| Product3 |
1500 |
1800 |
2100 |
2400 |
The company stores this information in a CSV file named "Quarterly_Sales.csv". Mr. Raj is asked for writing a Python program to visualise this data. He wrote the following Python code but encountered some difficulties. Help him by providing solutions to the following situations:
import pandas as pd
import ________________ as plt # line 1
df = ________________ # line 2
df.plot(__________='bar', color=['purple', 'orange', 'green', 'yellow']) # line 3
plt.title('Quarterly Sales Report') # line 4
plt.xlabel('Product')
plt.ylabel('Sales')
plt.show()
i. Choose the correct Python library from the following options to import in line 1:
a) matplotlib
b) matplotlib.plot
c) py.plot
d) matplotlib.pyplot
ii. Choose the correct option to specify the type of graph in line 3:
a) type
b) kind
c) style
d) graph
iii. Write suitable Python statement to fetch the data from 'Quarterly_Sales.csv' into the dataframe in line 2.
Ans: pd.read_csv('Quarterly_Sales.csv')
OR
Write Python statement to display total sales done in 'Qtr1' and 'Qtr2' for each product.
Ans: print(df['Qtr1']+df['Qtr2'])
SECTION E
33. Attempt the following questions:
(i) Write a SQL query to calculate the remainder when 15 is divided by 4.
Ans: SELECT MOD(15, 4) AS Remainder;
(ii) Write a SQL query to retrieve the current year.
Ans: SELECT YEAR(NOW()) AS CurrentYear;
(iii) Write a SQL query to extract the first three characters from the string 'Hello, World!'.
Ans: SELECT LEFT('Hello, World!', 3) AS ExtractedString;
(iv) Write a SQL query to convert the text in the 'description' column of the 'product' table to uppercase.
Ans: SELECT UPPER(description) AS UppercaseDescription FROM product;
(v) Write a SQL query to display the position of '-' in values of ACC_NO column of table Bank.
Ans: SELECT INSTR(acc_no, '-') FROM bank;
OR
Observe the given tables carefully and attempt the following questions:
Table: Bank
| ACC_NO |
BRANCH_NAME |
AMOUNT |
| B-70 |
Downtown |
5000 |
| B-230 |
Redwood |
6000 |
| B-260 |
Perryridge |
3700 |
Table: Customer
| CUSTOMER_NAME |
ACC_NO |
| Jones |
B-170 |
| Smith |
B-230 |
| Hayes |
B-155 |
(i) Identify the column based on which both the tables can be related or joined. Also justify your answer.
Ans: ACC_NO as it is present in both the tables having related values.
(ii) Write a SQL query to list names of all customers with their Amount in ascending order:
Ans: SELECT C.CUSTOMER_NAME, B.AMOUNT FROM CUSTOMER C JOIN BANK B ON C.ACC_NO = B.ACC_NO ORDER BY B.AMOUNT ASC;
(iii) Write a SQL query to find the total amount of money across all branches.
Ans: SELECT SUM(AMOUNT) AS TOTAL_AMOUNT FROM BANK;
(iv) Write a SQL query to count the total records in CUSTOMER table.
Ans: SELECT COUNT(*) from CUSTOMER;
(v) Write a SQL query to find the minimum amount in a bank.
Ans: SELECT MIN(AMOUNT) from BANK;
34. A large educational campus with multiple departments and buildings is planning to establish an efficient network infrastructure to connect its various facilities. The campus comprises five main buildings, each with specific distance and computer requirements:
Distance between various buildings:
Building A to Building B: 50 meters
Building B to Building C: 30 meters
Building C to Building D: 30 meters
Building D to Building E: 35 meters
Building E to Building C: 40 meters
Building D to Building A: 120 meters
Building D to Building B: 145 meters
Building E to Building B: 65 meters
Each building hosts a varying number of computers:
Building A: 55 computers
Building B: 180 computers
Building C: 60 computers
Building D: 55 computers
Building E: 70 computers
Based on the above specifications, answer the following questions:
(a) Suggest a possible cable layout for connecting the buildings in an efficient and effective way.
Ans:
(b) Name the topology used for above cable layout.
Ans: Star topology
(c) Suggest the most suitable place to install the server of this organisation.
Ans: Building B as it has maximum number of computers.
(d) Suggest the placement of the following devices:
(i) Hub/Switch (ii) Repeater
Ans: (i) Hub/Switch should be placed in each building.
(ii) Repeater is placed between Building B to building D.
(e) The company wants to link its head office in ‘A’ building to its Office in Sydney. What type of network this connection result into?
Ans: WAN
35. District wise total number of houses are represented in the following table:
| Dist VII |
Dist VIII |
Dist IX |
Dist X |
| 40 |
45 |
35 |
44 |
Draw the following bar graph representing the number of houses in each
District(Dist VII, Dist VIII, Dist IX, Dist X).
Also, give suitable python statement to save this chart in E: drive of the computer with name ‘house.png’.
Ans:
import matplotlib.pyplot as plt
district = ['VII','VIII','IX','X']
houses = [40,45,35,44]
plt.bar(district, houses)
plt.savefig('e:\house.png')
plt.show()
OR
Write a python program to plot a line chart based on the given data to depict the weekly study patterns for all the seven days.
Day = [1,2,3,4,5,6,7]
Study_Hours = [5,4,6,5,7,8,10]
Also, give suitable python statement to save this chart in d: drive of the computer with name ‘study.png’.
Ans:
import matplotlib.pyplot as plt
Day=[1,2,3,4,5,6,7]
Study_Hours=[5,4,6,5,7,8,10]
plt.plot(Day,Study_Hours)
plt.savefig('d:\study.png')
plt.show()