Final Vidhya LN Class 12 Practicals

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 55

PRESIDENCY

SCHOOL
BANGALORE SOUTH

PROGRAMMING
IN
PYTHON & SQL

Subject: COMPUTER SCIENCE

DONE BY:
VIDHYA LAKSHMINARAYANAN
XII ‘B’
2024-2025

CERTIFICATE

Name: VIDHYA LAKSHMINARAYANAN


Class: 12th ‘B’
Exam No: ____

This is certified to be the bonafide work of the student in the computer science
laboratory during the academic year 2024-2025.

__________________________
TEACHER INCHARGE

_______________________
____________
EXAMINER’S SIGNATURE

PRINCIPAL

Date: ______________

Institution Rubber stamp


INDEX

S.NO PROGRAM
.

1] Menu driven program:


 Factorial of a number.
 Fibonacci series up to nth term.
 Check a given number is Palindrome or not.
2] Menu driven program:
 Check a given number is Armstrong number or not.
 To display Floyd's triangle.
3] Menu driven program:
 Function to display the names starting with the alphabet ‘M’.
 Function to remove indicated letter from a string.
 Count number of words in a string.
4] Menu driven program (no built-in functions):
 Maximum of the element
 Minimum of the element
 Sum of the elements.
5] Menu driven program (Text file):
 Display the content line by line with each word separated by “$”.
 Remove the line which has ‘a’ and copy that line to another file.
6] Menu driven program (Text file):
 Create a file with several lines of text.
 Create another file which will store all the words starting with vowels.
 Read & display the contents of both the files.
 Display the total number of words starting with vowels.
7] Menu driven program (Text file):
 Create a file with a few lines of text.
 count number of lines, consonants, digits, spaces & words.
 Create another file which will contain the text after replacing all the
blank spaces with '#'.
 Read & display the contents of both the files.
8] Menu driven program (Text file):
 To read lines from text file and display those words which are less than
4 characters.
 to search a word and its frequency in a text file.
9] Menu driven program (Binary file):
 Create a file with the given structure.
 Read contents of the file and display the details of those students whose
percentage is above 75. Also display the number of students scoring
above 75%.
10] Menu driven program (Binary file):
 Create a file with the given structure.
 Display the contents of the binary file.
 Display the Company whose turnover is above user given value.
 Search a Company by Company ID given by the user.
11] Menu driven program (Binary file):
 Create a file with the given structure.
 Append data to the file and update a record based on travelid.
 Display the contents of the binary file.
12] Menu driven program (CSV file):
 Create a file with the given structure.
 read the file and calculate the total and percentage for each student.
 display the name of student if in any subject marks are greater than
80%.
13] Menu driven program (CSV file):
 Create a file with the given structure.
 to search the record and display the record, otherwise display
appropriate messages.
14] Menu driven program:
 To perform Push, Pop operations on the stack named ‘Hostel’ with the
given constraints.
15] Menu driven program:
 To perform Push, Pop operations on the stack named ‘Book’ with the
given constraints.
16] –
20] SQL Queries
21] –
24] Python – SQL Connectivity
QUESTION 1 Menu driven program:
 Factorial of a number.
 Fibonacci series up to nth term.
Check a given number is Palindrome or not.
QUESTION 2 Menu driven program:

➢ Check a given number is Armstrong number or not.

➢ To display Floyd's triangle.


QUESTION 3 Menu driven program:

➢ Function to display the names starting with the alphabet ‘M’.

➢ Function to remove indicated letter from a string.

➢ Count number of words in a string.


QUESTION 4 Menu driven program (no built-in functions):

➢ Maximum of the element

➢ Minimum of the element

➢ Sum of the elements.


QUESTION 5 Menu driven program (Text file):

➢ Display the content line by line with each word separated by “$”.

➢ Remove the line which has ‘a’ and copy that line to another file.

File one (before) File two File one (after)


QUESTION 6 Menu driven program (Text file):

➢ Display the content line by line with each word separated by “$”.

➢ Remove the line which has ‘a’ and copy that line to another file.
QUESTION 7 Menu driven program (Text file):

➢ Create a file with a few lines of text.

➢ count number of lines, consonants, digits, spaces & words.

➢ Create another file which will contain the text after replacing all the blank
spaces with '#'.

➢ Read & display the contents of both the files.


QUESTION 8 Menu driven program (Text file):

➢ To read lines from text file and display those words which are less than 4
characters.

➢ to search a word and its frequency in a text file.


QUESTION 9 Menu driven program (Binary file):

➢ Create a file with the given structure.

➢ Read contents of the file and display the details of those students whose
percentage is

above 75. Also display the number of students scoring above 75%.
QUESTION 10 Menu driven program (Binary file):

➢ Create a file with the given structure.

➢ Display the contents of the binary file.

➢ Display the Company whose turnover is above user given value.

➢ Search a Company by Company ID given by the user.


QUESTION 11 Menu driven program (Binary file):

➢ Create a file with the given structure.

➢ Append data to the file and update a record based on travelid.

➢ Display the contents of the binary file.


QUESTION 12 Menu driven program (CSV file):

➢ Create a file with the given structure.

➢ read the file and calculate the total and percentage for each student.

➢ display the name of student if in any subject marks are greater than 80%.
QUESTION 13 Menu driven program (CSV file):

➢ Create a file with the given structure.

➢ to search the record and display the record, otherwise display appropriate
messages.
QUESTION 14 Menu driven program:

➢ To perform Push, Pop operations on the stack named ‘Hostel’ with the given
constraints.
QUESTION 15 Menu driven program:

➢ To perform Push, Pop operations on the stack named ‘Book’ with the given
constraints.
SQL
16.Consider the following two tables: PRODUCT and CLIENT.
Table: Product

Table: Client

Write SQL statements for the following:


a. To display the ClientName and City of all Mumbai and Delhi-based
clients in the Client table.
b. Increase the price of all the products in the Product table by 10%.
c. To display the ProductName, Manufacturer, ExpiryDate of all the
products that expired on or before ‘2010-12-31’.
d. To display C_ID, ClientName, City of all the clients (including the ones
that have not purchased a product) and their corresponding ProductName
sold.
e. To display the total number of Manufacturer from the table Product.
f. To display C_ID, ClientName and City starts with the letter ‘M’ from the
table
Solution:
a. Select ClientName, City from Client where City = ‘Mumbai’ or City =
‘Delhi’;

b. Update Product set Price = Price + 0.10 * Price;

c. Select ProductName, Manufacturer, ExpiryDate from Product where


ExpiryDate < = ‘2010-12-31’;
d. Select C_ID, ClientName, City, ProductName from Client Left Join
Product on Client. P_ID = Product.P_ID;

e. Select COUNT(DISTINCT Manufacturer) from Product;

f. Select C_ID, Client_Name, City from Client where City Like ‘M%’;
17.Write SQL commands based on table SPORTS:

Table: SPORTS

a. Display the names of the students who have grade ‘C’ in either Game1 or
Game2 or both.
b. Display the number of students getting grade ‘A’ in Cricket.
c. Display the names of the students who have the same game for both
Game1 and Game2.
d. Display the game taken up by the students, whose name starts with ‘A’.
e. Add a new column named ‘Marks’.
f. Assign a value 200 for marks for all those who are getting grade ‘B’ or
grade ‘A’ in both Game1 and Game2.

Solution:

(a) SELECT Name for SPORTS where grade1=‘C’ or Grade2=‘C’;

(b) SELECT count(*) from SPORTS where grade=‘A’;


(c) SELECT name from SPORTS where game1 = game2;

(d) SELECT game,game2 from SPORTS where name like ‘A%’;

(e) ALTER TABLE SPORTS add (marks int(4));

(f) update sports set marks=200 where grade1='A' and grade2='B' or


grade2='A' and grade1='B' or grade1='A' and grade2='A' or grade 1='B'
and grade2='B';
18.Consider the following two tables: STATIONERY and CONSUMER.
Table: Stationery

Table: Consumer

Write SQL statements for the following:


a. To display details of all the Stationery Items in the Stationery table in
descending order of StockDate.
b. To display details of that Stationery item whose Company is XYZ and
price is below 10.
c. To display ConsumerName, Address from the table Consumer and
Company and Price from Stationery table, with their corresponding
S_ID.
d. To increase the price of all the stationery items in the Stationery table by
2.
e. To display number of Address from the table Consumer;
f. Select StationeryName, price * 3 from Stationery where Company =
‘CAM’;
Solution:
a. Select * from Stationery order by StockDate desc;
b. Select * from Stationery where Company = ‘XYZ’ and Price < 10;

c. Select ConsumerName, Address, Company, Price from Stationery,


Consumer where Stationery. S_ID = Consumer.P_ID;

d. Update Stationery Set Price = Price + 2;

e. select count(distinct address) from consumer;


f. Select StationeryName, price * 3 from Stationery where Company =
‘CAM’;

19.Create a table with constraints and Write SQL commands for the
following:
MOVIE
Movie_Id Movie_Name Type Cast Rating Qty Price
M001 Gone With the Drama Clark A 10 39
Wind Gable
M002 Doctor DoLittle Comedy Eddie B 3 40
Murphy
M003 Coyote Ugly Drama Piper C 4 35
Perabo
M004 Rush Hour Comedy Jackie A 5 1
Chan
M005 Bourne Identity Action Matt B 7 22
Damon
M006 Casino Royale Action Daniel B 3 90
Craig
M007 Runaway Bride Comedy Julia C 1 19
Roberts
a. Find the movies starring Julia Roberts.
b. To display the different types of movies available.
c. Display all movies which have a price range between 30 and 40.
d. Display all movies where the Rating is A
e. Display count of movies by type.
f. Display movie names which are starting from ‘R’.
ANSWERS
a. Select*from movie where cast = ‘Julia Roberts’;

b. Select distinct type from movie;

c. Select *from movie where price between 30 and 40;

d. Select*from movie where rating = ‘A’;


e. Select count(*) from movie group by type;

f. Select movie_name from movie where movie_name like ‘R%’;

20.Consider the following table:


Table: Employee

Table: Job

Write SQL Queries for the following:


a. To display employee ids, names of employees, job ids with
corresponding job titles.
b. To display names of employees, sales and job titles who have achieved
sales more than 1300000.
c. To display names and job titles who have ‘SINGH’ (anywhere) in their
names.
d. Write SQL command to change the jobid to 104 of the employee with ID
as E4 in the table Employee.
e. Display the contents of the tables.
f. Display the structure of the tables.
g. Show the average salary for all jobtitle with 2 or more than 2 for a job.
h. Display only the jobs with maximum salary greater than or equal to
80000.
i. Find out the number of employees having “manager” as job.
j. List the count of employees corresponding to their jobid.
k. List the sum of employees’ salaries corresponding to their jobtitle.
l. List the maximum salary of employees corresponding to their jobid.

Solution:
a. Select employeeid, name,job.jobid, jobtitle from employee, job
where employee.jobid = job.jobid;

b. Select name, sales, jobtitle from employee, job


where sales>1300000 and employee.jobid = job.jobid;

c. Select name, jobtitle from employee, job


where name like “%singh%” and employee.jobid = job.jobid;
d. Update employee set jobid=104 where employeeid = “E4”;

e. Select * from employee, job;


f. Desc employee;
desc job;

g. Select avg(salary), jobtitle from job group by jobtitle having


count(*)>=2;

h. Select jobtitle from job where salary>=80000;


i. Select jobtitle, count(*) from job where jobtitle like”%manager%”;

j. Select jobtitle, count(*) from job group by jobtitle;

k. Select sum(salary), jobtitle from employee , job


where employee.jobid = job.jobid group by jobtitle;

l. Select max(salary), job.jobid from employee, job


where employee.jobid = job.jobid group by job.jobid;
PYTHON SQL CONNECTIVITY
21. Write a menu-driven program in Python to establish connection between
Python and MySQL to create a table ‘PRODUCT’ with the following
description.

P_ID ProductName Manufacturer Pric ExpiryDate


e
TP01 Talcum Powder LAK 40 2011-06-26
FW05 Face Wash ABC 45 2010-12-01
BS01 Bath Soap ABC 55 2010-09-10
SH06 Shampoo XYZ 120 2012-04-09
FW12 Face Wash XYZ 95 2010-08-15

Perform following operations using the connection:


i) Insert at least 5 rows with appropriate data.
ii) To display the records in descending order of Price Column.
iii) Increase the price of all the products in Product table by 10%
ANSWER
22.Write a menu-driven program in Python to establish connection between
Python and MySQL to create a table ‘STATIONARY’ with the following
description.
S_ID StationaryName Company Pric StockDate
e
DP0 Dot Pen ABC 10 2011-03-31
1
PL02 Pencil XYZ 6 2010-01-01
ER0 Eraser XYZ 7 2010-02-14
5
PL01 Pencil CAM 5 2009-01-09
GP0 Gel Pen ABC 15 2009-03-19
2

Perform following operations using the connection


i) Insert at least 5 rows with appropriate data.
i) Increase the price of all the stationery items in Stationery table by 2
iii) To display details of that Stationery item whose Company is XYZ
23. Write a menu-driven program in Python to establish connection between
Python and MySQL to create a table ‘COMPANY’ with the following
description.

CID COMPANYNAME CITY PRODUCTNAME


111 Sony Delhi TV
222 Nokia Mumbai Mobile
333 Onida Delhi TV
444 Sony Mumbai Mobile
555 BlackBerry Bangalore Mobile
666 Dell Delhi Laptop

Perform following operations using the connection


i) Insert at least 5 rows with appropriate data.
ii) To display the company name which starts with ‘S’.
iii) To remove the records whose product name is ‘mobile’.
24. Write a menu-driven program in Python to establish connection between
Python and MySQL to create a table ‘EMPLOYEE’ with the following
description.

E_ID Fname Lname Hire_Date Salary


102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-05-2001 14000
105 Rashmi Malhotr 11-09-2004 11000
a

Perform following operations using the connection:


i) Insert at least 5 rows with appropriate data.
ii) To display F_ID, FirstName, LastName of all faculties whose
Salary is in the range of 10000 and 14000.
iii) To display the total of salary.

You might also like