0% found this document useful (0 votes)
3 views

12 CS24-25 Practical file

The document contains a comprehensive list of Python and MySQL programs, including tasks such as generating multiplication tables, checking characters, file manipulations, and database operations. Each program is briefly described with its purpose and expected output. Additionally, it includes SQL queries for creating and managing database tables, showcasing various functionalities like data retrieval and updates.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

12 CS24-25 Practical file

The document contains a comprehensive list of Python and MySQL programs, including tasks such as generating multiplication tables, checking characters, file manipulations, and database operations. Each program is briefly described with its purpose and expected output. Additionally, it includes SQL queries for creating and managing database tables, showcasing various functionalities like data retrieval and updates.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 44

INDEX

S Topic Pa Da Si
r ge te gn
No
N
.
o.
PYTHON PROGRAMS
1. Program to print a square multiplication table from 1 to
10

2. Program to check whether the given character is


alphabet or digit

3. Program that reads a string and checks whether it is


palindrome or not

4. Define two variables first and second so that first =


‘jimmy’ and second=’johny’. Write a short python code
segment that swaps the values assigned to these two
variables and prints the results.

5. Program using function that takes a number as an


argument and calculates cube for it.

6. Program For Factorial Of A Number

7. Program to find the Fibonacci series of a given number

8. Program to read a text file line by line and display each


word separated by a #

9. Program to read a text file and display the number of


vowels/consonants/uppercase/lowercase characters in the
fifile

1 Program to remove all the lines that contain the


character 'a' in a file and write it to another file
0.
1 Program to create a binary file with name and roll
number. Search for a given roll number and display the
1.
name, if not found display appropriate message

1 Create a binary file with roll number, name and marks.


Input a roll number and update the marks
2.
1 Write a function to count the number of lines in a text file
“My_Story.txt” that are starting with an alphabet “A”
3.
1 Program to create a CSV file by entering user_id and
password, read and search the password for given
4.
user_id

1 Write A Random Number Generator That Generates


Random Numbers Between
5.
1 And 6 (Simulates A Dice)

1 Write A Python Program To Implement A Stack Using A


List
6.

MySQL Programs
1. Create table Employee having EmpID, Name, Gender,
DOB with EmpID as

Primary key.

Write queries for the following:

a. Display the Table Structure

b. Add a Column department varchar(10),


Emp_Address(25)

c. Change the data type of the field Emp_Address to


varchar(50) and allow

Null values.

d. Delete the column DOB

e. Display all the records

2. Create table Customer as per following Table Instance


Chart.

a. Add one column Email of data type VARCHAR and size


30 to the table

Customer.

b. Add one column Email of data type VARCHAR and size


30 to the table

Customer.

c. Insert few records with relevant information, in the


table.

d. Drop the column CustomerIncomeGroup from table


Customer.

3. Create the following tables ‘Watches’ and ‘Sale’.

Write SQL queries for (a) to (d) and the output of SQL
commands for (e) to (h):
TABLE WATCHES
TABLE SALE

a. Display all the details of those watches whose name


end with “Time”

b. Display the name and price of those watches, which


have a price range in

between 5000 – 15000.

c. Display the total quantity in store of ‘Unisex’ type


watches.

d. Display the watch names and the quantity sold in the


first quarter.

e. SELECT MAX(PRICE), MIN(Qty_Store) FROM WATCHES;

f. SELECT MAX(PRICE), MIN(Qty_Store) FROM WATCHES;

g. SELECT WATCH_NAME, Qty_Store,

SUM(Qty_Sold),

QTY_Store-SUM(Qty_Sold) ‘’Stock’’ FROM WATCHES W,


SALE S

WHERE W.WATCHID = S.WATCHID

GROUP BY S.WATCHID;
4. Create the following tables for the database Library:

Table : BOOKS

Table : ISSUED

Write SQL queries for (a) to (f):

a. To show Book name, Author name and Price of books


of First Publ. publishers.

b. To list names from books of Text type.

c. To display the names and price from books in


ascending order of their price.

d. To increase price of price of all books of EPB and


Publishers by 50.

e. To display the Book_Id, Book_Name, and


Quantity_Issued for all books which

have been issued.(The query will require contents from


both the tables.)

f. To insert a new row in the table Issued having the


following data: “F003”, 1

g. Give the output of the following queries based on the


above tables:

(i). SELECT COUNT(*) FROM BOOKS;


(ii). SELECT MAX(Price) FROM Books WHERE QUANTITY
>=15;

(iii). SELECT Book_Name, Author_Name FROM Books


WHERE

Publishers=”EBP”;

(iv). SELECT COUNT(DISTINCT Publishers) FROM Books


WHERE Price>=400;

5. Consider the following DEPT and WORKER tables. Write


SQL queries for (i)

to and (iv) find outputs for SQL queries (v) to (viii) :

TABLE DEPT

TABLE WORKER

(i). To display Wno, Name, Gender from table WORKER in


descending order of

Wno.

(ii). To display the Name of all the FEMALE workers from


the table WORKER.

29 28.10.22

(iii). To display the Wno and Name of those workers from


the table WORKER who

are born between ‘1987-01-01’ and ‘1991-12-01’.

(iv). To count and display MALE workers who have joined


after ‘1986-01-01’.

(v). SELECT COUNT(*), DCODE FROM WORKER

GORUP BY DCODE HAVING COUNT(*)>1;

(vi). SELECT DISTINCT DEPARTMENT FROM DEPT;

(vii). SELECT NAME, DEPARTMENT, CITY FROM WORKER


W, DEPT D

WHERE

W.DCODE = D.DCODE AND WNO<1003;

(viii). SELECT MAX(DOJ), MIN(DOB) FROM WORKER;

Python Connectivity Programs


1. Write the code checking Python connectivity with MySQL
database namely,

School, and then fetch all the records from table


Employee.

2. Write a program for creating a database Student table


using Interface python with

MySQL.

3. Write a program to insert 10 records in above table and


display the same.

4. Program showing all Fetch commands


PYTHON
PROGRAM
S
Program 1 : Program to print a square multiplication table from 1 to 10

Code:-

Output:-
Program 2: Program to check whether the given character is alphabet or
digit

Code:-

Output:-
Program 3: Program that reads a string and checks whether it is
palindrome or not

Code:-

Output:-
Program 4: Define two variables first and second so that first = ‘jimmy’
and second=’johny’. Write a short python code segment that swaps the
values assigned to these two variables and prints the results.

Code:-
Output:-

Program 5: Program using function that takes a number as an argument


and calculates cube for it.

Code:-
Output:-

Program 6: Program For Factorial Of A Number

Code:-
Output:-

Program 7: Program to find the Fibonacci series of a given number

Code:-
Output:-

Program 8: Program to read a text file line by line and display each word
separated by a #

Code:-
Output:-

Text file:

Program 9: Program to read a text file and display the number of


vowels/consonants/uppercase/lowercase characters in the file
Code:-

Output:

Text document-

Program 10: .Program to remove all the lines that contain the character 'a'
in a file and write it to another file

Code:-
Output:-

Text file:-

Program 11: Program to create a binary file with name and roll number.
Search for a given roll number and display the name, if not found display
appropriate message
Code:-

Output:-

Program 12: Create a binary file with roll number, name and marks. Input
a roll number and update the marks

Code:
Output:

Program 13: .Write a function to count the number of lines in a text file
“My_Story.txt” that are starting with an alphabet “A”

Code:
Output:

Text File:

Program 14: .Program to create a CSV file by entering user_id and


password, read and search the password for given user_id

Code:-
Output:-

Program 15: Write A Random Number Generator That Generates Random


Numbers Between
1 And 6 (Simulates A Dice)

Code:
Output:

Program 16: Write A Python Program To Implement A Stack Using A List

Code:-
Output :-
MySQL
PROGRAM
S
Program 1) Create table Employee having EmpID, Name, Gender, DOB with EmpID as Primary key.

Write queries for the following:

a. Display the Table Structure

b. Add a Column department varchar(10), Emp_Address(25)

c. Change the data type of the field Emp_Address to varchar(50) and allow Null values.

d. Delete the column DOB

e. Display all the records

Code:
Program 2) Create table Customer as per following Table Instance Chart

a. Add one column Email of data type VARCHAR and size 30 to the table Customer.

b. Add one column Email of data type VARCHAR and size 30 to the table Customer.

c. Insert few records with relevant information, in the table.

d. Drop the column CustomerIncomeGroup from table Customer

Code:

Program 3)Create the following tables ‘Watches’ and ‘Sale’


Write SQL queries for (a) to (d) and the output of SQL commands for (e) to (h):

Table Watches:

Table Sale:

a. Display all the details of those watches whose name end with “Time”

b. Display the name and price of those watches, which have a price range in between 5000 –
15000. c. Display the total quantity in store of ‘Unisex’ type watches.

d. Display the watch names and the quantity sold in the first quarter.

e. SELECT MAX(PRICE), MIN(Qty_Store) FROM WATCHES;

f. SELECT MAX(PRICE), MIN(Qty_Store) FROM WATCHES;

g. SELECT WATCH_NAME, Qty_Store, SUM(Qty_Sold), QTY_Store-SUM(Qty_Sold) ‘’Stock’’ FROM


WATCHES W, SALE S WHERE W.WATCHID = S.WATCHID GROUP BY S.WATCHID;

Code:
Program 4) Create the following tables for the database Library

Table Books:

Table Issued:

Write SQL queries for (a) to (f):

a. To show Book name, Author name and Price of books of First Publ. publishers.

b. To list names from books of Text type.

c. To display the names and price from books in ascending order of their price.

d. To increase price of price of all books of EPB and Publishers by 50.

e. To display the Book_Id, Book_Name, and Quantity_Issued for all books which have been
issued.(The query will require contents from both the tables.)

f. To insert a new row in the table Issued having the following data: “F003”, 1

g. Give the output of the following queries based on the above tables:

(i). SELECT COUNT(*) FROM BOOKS;

(ii). SELECT MAX(Price) FROM Books WHERE QUANTITY >=15;

(iii). SELECT Book_Name, Author_Name FROM Books WHERE Publishers=”EBP”;

(iv). SELECT COUNT(DISTINCT Publishers) FROM Books WHERE Price>=400;


Code:
Program 5)Consider the following DEPT and WORKER tables. Write SQL queries for (i) to (iv).
Find SQL queries (v) to (viii):

(i). To display Wno, Name, Gender from table WORKER in descending order of Wno.

(ii). To display the Name of all the FEMALE workers from the table WORKER.

(iii). To display the Wno and Name of those workers from the table WORKER who are born
between ‘1987-01-01’ and ‘1991-12-01’.

(iv). To count and display MALE workers who have joined after ‘1986-01-01’.

(v). SELECT COUNT(*), DCODE FROM WORKER GORUP BY DCODE HAVING COUNT(*)>1;

(vi). SELECT DISTINCT DEPARTMENT FROM DEPT;

(vii). SELECT NAME, DEPARTMENT, CITY FROM WORKER W, DEPT D WHERE W.DCODE =
D.DCODE AND WNO<1003;

(viii). SELECT MAX(DOJ), MIN(DOB) FROM WORKER;


Code:
PYTHON
CONNECTI
VITY
PROGRAM
S
Program 1: Write the code checking Python Connectivity with MySQL database namely, School, and then fetch all
records from table Employee

Code:
No error indicates successful execution!

Table Employee created in MySQL Command Line Client:

Program to fetch Employee:

Output:

Program 2: Write a program for creating database student table using Interface Python with MySQL
Code:

Output: Table Created

Program 3: Write a program to insert 10 records in the above table and display the same

Code:
Output:

Displaying output in SQL window:

Program 4: Write a program showing all Fetch commands

Code:
Output:

You might also like