0% found this document useful (0 votes)
2 views4 pages

Question

The document contains Python code for reading a text file and displaying words that start with vowels, as well as a stack implementation for student marks using a dictionary. It also includes SQL queries for retrieving specific information from DEPT and WORKER tables in a database. The SQL queries cover selecting worker details based on various criteria such as gender and date of joining.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Question

The document contains Python code for reading a text file and displaying words that start with vowels, as well as a stack implementation for student marks using a dictionary. It also includes SQL queries for retrieving specific information from DEPT and WORKER tables in a database. The SQL queries cover selecting worker details based on various criteria such as gender and date of joining.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Question: -

Write a Python Program to read a text file line by line and display those words of each
line which started with any vowel character.
Code: -

file = open("[Link]", "r")

for line in file:


words = [Link]()
for word in words:
if word[0].lower() in ['a', 'e', 'i', 'o', 'u']:
print(word, end=" ")
print()

[Link]()
Output:-
Question:-
Create a Python program to create a stack of student’s marks, which retrieves the
information from a dictionary.
Stud = {'Amit': 40, 'Rajeev': 59, 'Nilam': 75, 'Sanyam': 49}
 Write function PUSH(Student) to add marks of those students which have marks
more than 50 from a dictionary Student, and
 Write function POP to remove the marks from stack and display the same
Code:-

Stud = {'Amit': 40, 'Rajeev': 59, 'Nilam': 75, 'Sanyam': 49}

stack = []

def PUSH(Student):
for name, marks in [Link]():
if marks > 50:
[Link]((name, marks))
print("Stack after PUSH operation:", stack)

def POP():
if len(stack) == 0:
print("Stack is empty")
else:
popped_item = [Link]()
print("Popped element:", popped_item)

PUSH(Stud)
POP()
POP()
Output:-
Question: -
Consider the following DEPT and WORKER tables.
Write SQL queries for (i) to (iv):

Table: DEPT
DCO DEPARTMENT CITY
DE
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTUR MUMBA
E I
D05 FINANCE KOLKAT
A
D04 HUMAN MUMBA
RESOURCE I

Table: WORKER
WN NAME DOJ DOB GEND DCO
O ER DE
100 George K 2013-09- 1991-09- MALE D01
1 02 01
100 Ryma Sen 2012-12- 1990-12- FEMAL D03
2 11 15 E
100 Mohitesh 2013-02- 1987-09- MALE D05
3 03 04
100 Anil Jha 2014-01- 1984-10- MALE D04
7 17 19
100 Manila 2012-12- 1986-11- FEMAL D01
4 Sahai 09 14 E
100 R SAHAY 2013-11- 1987-03- MALE D02
5 18 31
100 Jaya Priya 2014-06- 1985-06- FEMAL D05
6 09 23 E

Questions
a) To display WNO, Name, Gender from the table WORKER in descending order
of WNO.
b) To display the Name of all the FEMALE workers from the table WORKER.
c) To display the WNO and Name of those workers from the table WORKER who are
born between
'1987-01-01' and '1991-12-01'.
d) To display all the MALE workers who have joined after '1986-01-01'.
Code:-
CREATE DATABASE COMPANY;

USE COMPANY;

CREATE TABLE DEPT (


DCODE CHAR(3) PRIMARY KEY,
DEPARTMENT VARCHAR(30),
CITY VARCHAR(20)
);

INSERT INTO DEPT VALUES ('D01', 'MEDIA', 'DELHI');


INSERT INTO DEPT VALUES ('D02', 'MARKETING', 'DELHI');
INSERT INTO DEPT VALUES ('D03', 'INFRASTRUCTURE', 'MUMBAI');
INSERT INTO DEPT VALUES ('D05', 'FINANCE', 'KOLKATA');
INSERT INTO DEPT VALUES ('D04', 'HUMAN RESOURCE', 'MUMBAI');

CREATE TABLE WORKER (


WNO INT PRIMARY KEY,
NAME VARCHAR(30),
DOJ DATE,
DOB DATE,
GENDER VARCHAR(10),
DCODE CHAR(3)
);

INSERT INTO WORKER VALUES


(1001, 'George K', '2013-09-02', '1991-09-01', 'MALE', 'D01'),
(1002, 'Ryma Sen', '2012-12-11', '1990-12-15', 'FEMALE', 'D03'),
(1003, 'Mohitesh', '2013-02-03', '1987-09-04', 'MALE', 'D05'),
(1007, 'Anil Jha', '2014-01-17', '1984-10-19', 'MALE', 'D04'),
(1004, 'Manila Sahai', '2012-12-09', '1986-11-14', 'FEMALE', 'D01'),
(1005, 'R Sahay', '2013-11-18', '1987-03-31', 'MALE', 'D02'),
(1006, 'Jaya Priya', '2014-06-09', '1985-06-23', 'FEMALE', 'D05');

a)
SELECT WNO, NAME, GENDER
FROM WORKER
ORDER BY WNO DESC;

b)
SELECT NAME
FROM WORKER
WHERE GENDER = 'FEMALE';

c)
SELECT WNO, NAME
FROM WORKER
WHERE DOB BETWEEN '1987-01-01' AND '1991-12-01';

d)
SELECT *
FROM WORKER
WHERE GENDER = 'MALE'
AND DOJ > '1986-01-01';

You might also like