Set Ans
Set Ans
def POP(stk):
if len(stk)==0:
print('STACK UNDERFLOW')
else:
c=stk.pop()
print('The popped city is:',c)
def DISPLAY(stk):
if len(stk)==0:
print('STACK EMPTY')
else:
print("The stack elements are:")
print(stk[-1],'<--TOP')
for i in reversed(stk[:-1]):
print(i)
(e) Write a Query to List all the tables that exists in the current database.
ANS) SHOW TABLES;
SET – 2
1. Creating a python program to create and search employee’s record in
csv file.
ANS)
import csv
def addrec():
a = open('emp.csv','w',newline='')
b=csv.writer(a)
l=[]
ans='y'
while ans=='y':
eno=int(input("Enter the emp no:"))
ename=input("Enter emp name :")
s=int(input("Enter emp salary:"))
l.append([eno,ename,s])
ans=input("Do you want to add another record(y/n):")
b.writerows(l)
print("record stored")
a.close()
def searchrec():
a = open('emp.csv','r',newline='')
b = csv.reader(a)
s=int(input('Enter the emp no which you want to search:'))
for i in b:
if i[0]==str(s):
print("The details found are:",i)
break
else:
print('no record found')
a.close()
print("Employee details - search record program")
addrec()
searchrec()
2. TABLE - STU
Rollno Name Gender Age Dept DOA Fees
1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200
(CREATE DATABASE, USE, CREATE TABLE, INSERT COMMANDS ARE MANDATORY)
(b) Write a Query to display all the details of the Employees from the above table 'STU'.
ANS) SELECT * FROM STU;
(c) Write a query to display Rollno, Name and Department from STU table.
ANS) SELECT ROLLNO,NAME,DEPT FROM STU;
(b) Write a Query to list name of the students whose age’s are between 18 to 20.
ANS) SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;
(c) Write a Query to display the names of the students whose name is starting with 'A'.
ANS) SELECT NAME FROM STU WHERE NAME LIKE 'A%';
(d) Write a query to list the names of those students whose name have second alphabet
'n' in their names.
ANS) SELECT NAME FROM STU WHERE NAME LIKE '_N%';
SET – 4
1. Creating a python program to copy particular lines of a text file into
another text file.
ANS)
f=open('sample.txt', 'r')
a=f.readlines()
f.close()
f=open('sample.txt','w')
f1=open('sample1.txt','w')
for i in a:
if ('a' in i )or ('A' in i):
f1.write(i)
else:
f.write(i)
f.close()
f1.close()
2. TABLE - STU
Rollno Name Gender Age Dept DOA Fees
1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200
(CREATE DATABASE, USE, CREATE TABLE, INSERT COMMANDS ARE MANDATORY)
(b) Write a Query to change the fess of Student to 170 whose Roll number is 1, if
the existing fess is less than 130.
ANS) UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130;
(c) Write a Query to add a new column named Area of type varchar in table STU.
ANS) ALTER TABLE STU ADD AREA VARCHAR(20);
(d) Write a Query to Display Name of all students whose Area Contains NULL.
ANS) SELECT NAME FROM STU WHERE AREA IS NULL;
(e) Write a Query to delete Area Column from the table STU.
ANS) ALTER TABLE STU DROP AREA;
2. TABLE - STU
Rollno Name Gender Age Dept DOA Fees
1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200
(CREATE DATABASE, USE, CREATE TABLE, INSERT COMMANDS ARE MANDATORY)
(j) Write a Query to List all the tables that exists in the current database.
ANS) SHOW TABLES;
SET – 6
1. Creating a python program to read a text file line by line and display
each word separated by '#'.
ANS)
a=open('sample.txt','r')
b=a.readline()
while b:
c=b.split()
for i in range(len(c)-1):
print(c[i],'#',end='')
print(c[-1])
print()
b=a.readline()
a.close()
3. TABLE - STU
Rollno Name Gender Age Dept DOA Fees
1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200
(CREATE DATABASE, USE, CREATE TABLE, INSERT COMMANDS ARE MANDATORY)
(b) Write a Query to display all the details of the Employees from the above table 'STU'.
ANS) SELECT * FROM STU;
(f) Write a query to display Rollno, Name and Department from STU table.
ANS) SELECT ROLLNO,NAME,DEPT FROM STU;
3. TABLE - STU
Rollno Name Gender Age Dept DOA Fees
1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200
(CREATE DATABASE, USE, CREATE TABLE, INSERT COMMANDS ARE MANDATORY)
(b) Write a Query to list name of the students whose age’s are between 18 to 20.
ANS) SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;
(e) Write a Query to display the names of the students whose name is starting with 'A'.
ANS) SELECT NAME FROM STU WHERE NAME LIKE 'A%';
(f) Write a query to list the names of those students whose name have second alphabet
'n' in their names.
ANS) SELECT NAME FROM STU WHERE NAME LIKE '_N%';
SET – 8
1. Creating a python program to generate random number between
1 to 6.
ANS)
import random
print("Dice game ")
print("Game starts...")
ans='yes'
while ans.lower()=='yes':
print("Dice rolling ")
s=random.randint(1,6)
print("You got:",s)
ans=input("Do you want to roll again the dice (yes/no):")
print("See you again.. Bye")
a) To Display the average price of all the Uniform of Raymond Company from table COST.
ANS) SELECT AVG(PRICE) FROM COST WHERE COMPANY='RAYMOND';
b) To display details of all the Uniform in the Uniform table in descending order of Stock
date.
ANS) SELECT * FROM UNIFORM ORDER BY STOCKDATE DESC;
d) To display the company where the number of uniforms size is more than 2.
ANS) SELECT COMPANY, COUNT(*) FROM COST GROUP BY COMPANY HAVING
COUNT(*)>2;
e) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.
ANS) SELECT U.UCODE,UNAME,UCOLOR,SIZE,COMPANY FROM UNIFORM U,COST C
WHEREU.UCODE=C.UCODE;