Term II Practical List CS
Term II Practical List CS
Computer Science
Term II Practical List (2023-24)
Std XII
1.Write a program to create a Stack for storing only odd numbers out of all the numbers entered by the
user. Display the content of the Stack along with the largest odd number in the Stack.
2. Write a menu drive program in python to implement stack using a list and perform following function :
Push
Pop,
Display
Peek
# Program introduction statement
print("Simple STACK Data Structure Program")
# USER enter option 2 then POP one element from the STACK
elif choice == 2:
if len(stack) == 0: # Check whether STACK is Empty or not
print('The STACK is EMPTY No element to POP out')
# Display this ERROR message if STACK is Empty
else:
# pop() function to POP element from the STACK in LIFO order
print('\nElement POP out from the STACK is:')
print(stack.pop()) # Display the element which is POP out from the STACK
3
.
6. Write a program to create csv file and store empno,name and salary of employee .
import csv
fh=open('pt2-csv.csv','w',newline='')
obj=csv.writer(fh,delimiter=',')
n=int(input("Enter the no.of employees:"))
for i in range(n):
e_no=int(input("Enter the employee number:"))
e_name=input("Enter the employee name:")
e_salary=int(input("Enter the salary:"))
obj.writerow([e_no,e_name,e_salary])
fh.close()
fh=open('pt2-csv.csv','r')
obj=csv.reader(fh,delimiter=',')
e=int(input("enter the employee number to be searched:"))
for i in obj:
if int(i[0])==e:
print("Record found")
print("Name:",i[1])
print("Salary",i[2])
break
else:
print("Record not found")
break
fh.close()
7. Write a SQL statement to create Database named WORLD ,inside it create table named COUNTRIES including
columns Country_ID, Country_Name, ,Language, Cuisine and Population. country ID column will not contain any null
value and duplicate data .
2. USE database_name;
3. CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
Example:
CREATE TABLE Countries (
Country_ID int not null primarykey,
Country_name varchar(255),
Capital varchar(255),
Cuisine varchar(255),
Population int(255)
);
4. NSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
8. Create following tables such that Empno and Sno are not null and unique, date of birth is after '12-Jan-1960',
name is never blank, Area and Native place is valid, hobby, dept is not empty, salary is between 4000 and 10000.
Table: Personal
Table: job
(a) Show empno, name and salary of those who have Sports as hobby.
(b) Show name of the eldest employee.
(c) Show number of employee area wise.
(d) Show youngest employees from each Native place.
(e) Show Sno, Name, Hobby and Salary in descending order of Salary.
(f) Show the hobbies of those whose name pronounces as 'Abhay'.
(g) Show the appointment date and native place of those whose name starts with 'A' or ends in
'd'.
(h) Show the salary expense with suitable column heading of those who shall retire after 20-jan-
2006.
(i) Show additional burden on the company in case salary of employees having hobby as sports,
is increased by 10%.
(j) Show the hobby of which there are 2 or more employees.
(k) Show how many employee shall retire today if maximum length of service is 20 years.
(l) Show those employee name and date of birth who have served more than 17 years as on date.
(m) Show names of those who earn more than all of the employees of Sales dept.
(n) Increase salary of the employees by 5% of their present salary with hobby as Music or they
have completed at least 3 years of service.
(o) Write the output of:
(p) Add a new tuple in the table Personal essentially with hobby as Music.
(q) Insert a new column email in Job table.
(r) Create a table with values of columns empno, name, and hobby.
(s) Create a view of Personal and Job details of those who have served less than 15 years.
(t) Erase the records of employee from Job table whose hobby is not Sports.
(u) Remove the table Personal.
Answer :-(a)Select empno , name , salary from personal , Job where Empno = Sno and Hobby = “Sports” ;
(b)Select * from personal where (select min( dobirth ) from personal ) = dobirth ;
(c)Select count(name ) , from Personal , Job where Empno = Sno group by Area ;
(e)Select Sno,Name , Hobbay , Salary from Personal , Job where Empno = Sno order by Salary desc ;
(g)Select App_date , Native -place from Personal , Job where Empno = Sno and Name like “A%” or name like
“%r” ;
(h)Select salary as ' salary expense' from personal P, job J where p.empno=J.sno AND retd_date< '20160120' ;
(i)Select ( sum ( Salary ) * 0.10 ) as “Additional_burden” from Personal , Job where Empno = Sno and
Hobby = “Sports” ;
(k)Select name from personal , job where empno = sno and ( curdate( ) - app_date ) >= 200000 ;
(l)Select name , Dobrirth from personal , job where empno = Sno and ( curdate() - app_date ) > 170000 ;
(m) Select Name from Personal, Job where Empno = Sno and Dept = “Sales” Order by max( Salary) in
('Sales');
(o)(i)
distinct hobby
Music
Writing
Sports
Gardening
avg(salary)
6333.3333 (ii)
count(distinct Native_place)
4 (iii)
Name Max(salary)
Vinod 8500 (iv)
(s)Select * from personal , job where empno = sno and ( retd_date - app_date ) < 150000 ;
(t) Delete from job, personal where empno = Sno and hobby < > “Sports” ;
import mysql.connector
con=mysql.connector.connect(host="localhost",user="ASP",password="student")
if con.is_connected():
print("connnection successfully")
cur=con.cursor()
_________________________________________________________________________________
# To use Database
import mysql.connector
con=mysql.connector.connect(host="localhost",user="ASP",password="student",database="India")
if con.is_connected():
print("connnection successfully")
cur=con.cursor()
10. Write a python database connectivity Script that Insert values into Table .
import mysql.connector
con=mysql.connector.connect(host="localhost",user="ASP",password="student",database="abroad")
#if con.is_connected():
#print("connnection successfully")
cur=con.cursor()
while True:
cur.execute(query)
con.commit()
if ch=='n':
break
OR
import mysql.connector
con=mysql.connector.connect(host="localhost",user="ASP",password="student",database="abroad")
cur=con.cursor()
record=[(10,"goregao","eng"),(20,"goregao","eng"),(30,"gurugram","eng") ]
cur.executemany(query,record)
con.commit()
____________________________________________________________________________________
11. Write a python database connectivity Script that shows table of database .
import mysql.connector
con=mysql.connector.connect(host="localhost",user="ASP",password="student",database="abroad")
cur=con.cursor()
for i in cur:
print(i)
12. Write a python database connectivity Script that delete records from category table of database items .
import mysql.connector
con=mysql.connector.connect(host="localhost",user="ASP",password="student",database="items")
cur=con.cursor()
sql1=”DELETE FROM category WHERE name=’%s’”
data1=(‘stockble’,)
cur.execute(sql1,data1)
con.commit()
print(cur.rowcount,"Rows affected:")
con.close()
13. Write a python database connectivity Script that displays first three rows fetched from student table of
MYSQL,database””Test.
import mysql.connector
con=mysql.connector.connect(host="localhost",user="ASP",password="student",database="items")
cur=con.cursor()
cur.execute(“select * from student”)
data=cursor.fetchmany(3)
count=cursor.rowcount
for row in data:
print(row)
mycon.close()