0% found this document useful (0 votes)
74 views9 pages

Term II Practical List CS

The document contains the practical list for Class 12 Computer Science students of Seth Hirachand Mutha School for Term II of the academic year 2023-24. It includes 10 programming problems related to stacks, CSV files, SQL queries, database connectivity in Python, and more. Students are expected to write Python programs and SQL queries to implement stacks, read and write to CSV files, create and insert values into databases, and perform various operations on tables like selecting, updating, deleting records.

Uploaded by

rssbasdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views9 pages

Term II Practical List CS

The document contains the practical list for Class 12 Computer Science students of Seth Hirachand Mutha School for Term II of the academic year 2023-24. It includes 10 programming problems related to stacks, CSV files, SQL queries, database connectivity in Python, and more. Students are expected to write Python programs and SQL queries to implement stacks, read and write to CSV files, create and insert values into databases, and perform various operations on tables like selecting, updating, deleting records.

Uploaded by

rssbasdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Seth Hirachand Mutha School

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")

# Initial empty STACK


stack = []

# Display Menu with Choices


while True:
print("\nSELECT APPROPRIATE CHOICE")
print("1. PUSH Element into the Stack")
print("2. POP Element from the Stack")
print("3. Display Elements of the Stack")
print("4. Exit")
choice = int(input("Enter the Choice:")) # Taking input from the user regarding choice

# USER enter option 1 then PUSH elements into the STACK


if choice == 1:
# append() function to PUSH elements into the STACK
stack.append("Monday") # PUSH element Monday
stack.append("Tuesday") # PUSH element Tuesday
stack.append("Wednesday") # PUSH element Wednesday
stack.append("Thursday") # PUSH element Thursday
stack.append("Friday") # PUSH element Friday
stack.append("Saturday") # PUSH element Saturday
stack.append("Sunday") # PUSH element Sunday
stack.append('8') # PUSH element 8
print('\nTotal 8 elements PUSH into the STACK')

# 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

# USER enter option 3 then display the STACK


elif choice == 3:
if len(stack) == 0: # Check whether STACK is Empty or not
print('The STACK is initially EMPTY') # Display this message if STACK is Empty
else:
print("The Size of the STACK is: ",len(stack)) # Compute the size of the STACK
print('\nSTACK elements are as follows:')
print(stack) # Display all the STACK elements

# User enter option 4 then EXIT from the program


elif choice == 4:
break

# Shows ERROR message if the choice is not in between 1 to 4


else:
print("Oops! Incorrect Choice")

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 .

Country_ID Country_Name Capital Cuisine Population

C001 India Delhi Vada Pav 140.76


C002 USA Washington barbecue 33.19
C003 China Beijing Shandong 141.24
C004 Australia Canberra sausage sizzle 2.57
C005 Germany Berlin Spaghettieis 8

1. CREATE DATABASE database_name ;

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 ;

(d)Select name from personal Group by Native-place Order by max(dobirth) ;

(e)Select Sno,Name , Hobbay , Salary from Personal , Job where Empno = Sno order by Salary desc ;

(f)Select Hobby from Personal where name = “Abhay” ;

(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” ;

(j)Select Hobby from Personal group by hobby having Count(*) >= 2 ;

(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');

(n) Update Personal , job


set salary = salary + 0.05 * salary
where Empno = Sno and Hobby = “Music”
or ( curdate() - App_date ) >= 30000 ;

(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)

(p)Insert into Personal (Hobby) values (135,"PathWalla", 20081990, "Lucknow" “Music”);

(q)Alter table Job add column email char(100) ;

(r)Create table new_table (Select Empno , name,Hobby from Personal);

(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” ;

(u) Drop Table Personal;

9. Write a python database connectivity Script that To create database .

import mysql.connector

con=mysql.connector.connect(host="localhost",user="ASP",password="student")

if con.is_connected():

print("connnection successfully")

cur=con.cursor()

cur.execute("create database India") # Database created,you can check in Mysql

print ("query successfully executed")

_________________________________________________________________________________

# 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()

cur.execute("create Table Maharashtra(C_Code int,c_name varchar(10),language varchar(20))") # No need to repeat


this query again

print ("table successfully executed")


_______________________________________________________________________________________________

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:

C_Code=int(input("Enter city code:"))

c_name=input("Enter Book name:")

language=input("Enter city language")

query="insert into Maldivs values({},'{}','{}')".format(C_Code,c_name,language)

cur.execute(query)

con.commit()

print("Row inserted successfully")

ch=input("Do u want to insert new record?(y/n)")

if ch=='n':

break

OR

import mysql.connector

con=mysql.connector.connect(host="localhost",user="ASP",password="student",database="abroad")

cur=con.cursor()

query="insert into Maldivs(C_Code,c_name,language)values(%s,%s,%s)"

record=[(10,"goregao","eng"),(20,"goregao","eng"),(30,"gurugram","eng") ]

cur.executemany(query,record)

con.commit()

print(cur.rowcount,"multiple record inserted")

____________________________________________________________________________________

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()

cur.execute(" show tables")

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()

You might also like