0% found this document useful (0 votes)
4 views48 pages

CS Practical File09

The document outlines a series of assignments related to Python programming, MySQL queries, and data structures, divided into four parts. Part A focuses on Python programs including functions, exception handling, and file handling, while Part B covers MySQL commands and queries. Parts C and D address Python database connectivity and advanced data structures like queues and CSV file handling.

Uploaded by

kakransinaryan
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)
4 views48 pages

CS Practical File09

The document outlines a series of assignments related to Python programming, MySQL queries, and data structures, divided into four parts. Part A focuses on Python programs including functions, exception handling, and file handling, while Part B covers MySQL commands and queries. Parts C and D address Python database connectivity and advanced data structures like queues and CSV file handling.

Uploaded by

kakransinaryan
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

Index

[Link]. Assignment Date Page No. Sign.

Part A – Python Programs

Python Revision Tour

1 List Menu Driven Program 7

2 Dictionary Menu Driven Program 8

Working with Functions

Using a function to display prime


3 9
numbers between m & n.

Using a function calculate


4 10
interest using various arguments.

Using a function find a largest


5 element in a list. Pass list object 11
as argument.

Using a function count the


6 number of vowels in passed 12
string.

Exception Handling

Take two integers and perform


addition of two numbers handle
7 13
exception when non-integers
entered by user

Find the square root of a positive


number, raise a custom
8 14
exception when user enters a
negative number
[Link]. Assignment Date Page No. Sign.

File handling

Find and replace a word in a text


9 15
file

Menu driven program for binary


10 file to insert, update, delete and 16
display records

Menu driven program for csv file


11 to insert, update and delete 20
records

Search record in binary file using


12 22
user defined condition

Search record in csv file using


13 23
user defined condition

Data Structure - Stack

Menu driven program for stack


14 26
operations

Searching data from dictionary


15 and transfer keys into stack then 29
performing push operations

Part B – MySQL Queries

Set 1 – Based on Database Basic


16 31
Commands

17 Set 2 – Based on DDL Commands 32

Set 3 – Select Queries including


18 35
order by

Set 4 – Group by, having and


19 37
Aggregate Functions

20 Set 5 – Join Queries 39


[Link]. Assignment Date Page No. Sign.

Part C – Python Database Connectivity

21 Insert record in a database table 41

Update a record in a database


22 42
table

Delete a record in a database


23 43
table

Display records using queries


24 44
from database table

Part-D Data Structure 2 (Queue and CSV)

Store and search record in


25 45
CSV file

Implement Queue in Python


26 46
using list

Find most common word


27 49
occurring in phishing mails

Create 21 Stick Game such


28 50
that computer always wins
Part A – Python Programs
Chapter 1 - Python Revision Tour

1. Write a program to find the sum and average of list in python.

SOURCE CODE:

OUTPUT:
2. Write a program to remove duplicates from the dictionary .

SOURCE CODE:

OUTPUT:
Chapter 2 – Working with functions

3. Write a program to define a function to accept two integers m and


n respectively as argument and display prime numbers between
them.

SOURCE CODE:

OUTPUT:
4. Write a program to compute interest based on different arguments
given in the function.

SOURCE CODE:

OUTPUT:
5. Write a program to largest element in a list using a function. Pass
list object as argument.

SOURCE CODE:

OUTPUT:
6. Write a program to count the number of vowels in passed string to
the function.

SOURCE CODE:

OUTPUT:
Chapter 3 – Exception Handling

7. Write a program to take two integers and perform addition of two


numbers handle exception when non-integers entered by user.

SOURCE CODE:

OUTPUT:
8. Write a program to find the square root of a positive number, raise
a custom exception when user enters a non-integer number.

SOURCE CODE:

OUTPUT:
Chapter 4 – File Handling

9. Write a program to replace entered word from a text file [Link].

SOURCE CODE:

OUTPUT:
Chapter 4 – File Handling

10. Write a menu driven program to store and manipulate data in


binary file to insert, update, delete and display records. The data
has following structure:
Menu:
Data Represents - Patient Information
1. Add Patient
Dictionary - {‘P_ID’:101,’P_Name’:’Shiv’,’Charges’:25000}
2. Display Patient
File Name - [Link] 3. Search Patient
4. Update Patient
5. Delete Patient
6. Exit

SOURCE CODE:
OUTPUT:
11. Create a CSV file by entering user-id and password, read and
search the password for given userid.

SOURCE CODE:
OUTPUT:
12. Write a program to create a binary file [Link] which
stores the following information in list as follows:
Structure of Data
Field Data - Type
Candidate_id - Integer
Candidate_Name - String
Designation - String
Experience - Float
(i)Write a function append() to write data into binary file.
(ii) Write a function display() to display data from binary file for all
candidates whose experience is more than 10.

SOURCE CODE:

OUTPUT:
13. Write a program to generate a CSV file named [Link].
Each record of CSV contains these data:
Name of the country - String
Population of country - Integer
No. people participated in survey - Integer
No. of people who are Happy - Integer
Write user defined functions to do the following:
(i) Insert records into CSV
(ii) Display records from CSV
(iii)Update records
(iv)Delete record

SOURCE CODE:
OUTPUT:
14. Write a menu drive program for stack operations:

SOURCE CODE:
OUTPUT:
15. Write a program to Push an item into stack where a dictionary
contains the details of stationary items as follows:
stn = {“Shirt”:700,”T-Shirt”:750,”Jeans”:1150,”Trouser”:400}
(a) Write a function to push an element into stack for those
items names whose price is more than 850. Also display the
count of elements pushed into the stack.
(b) Write a function to pop an element to remove the element
and display appropriate message when the stack is empty

SOURCE CODE:
OUTPUT:
Part B – MySQL Queries
Chapter 11 – Simple Queries in SQL

Set 1 – Based on Database Basic Commands


Write SQL Commands for following:

1. Create a database named practical_2025.

2. Check database is present or not in the list of databases.

3. Open a database.

4. Create a database temp.

5. Delete a database temp.


Set 2 – Based on DDL Commands

Consider the following MOVIES table and write the SQL commands
based on it.

1. Create above table, assign Movie_ID as a primary key and insert


records as above.
2. Show the structure of table

3. Add a column named collection with decimal data type with


structure 12, 2

4. Change the data type of movie_id to varchar

Table Affected:
5. Rename a column MovieName to MName

6. Delete a column collection


Set 3 – Select queries including order by

1. Display the movie name, type, releasedate and total cost of all
movies

2. Display all details of action and thriller movies

3. Display movie name, types and releasedate of all movies released


in the month of February, 2022

4. Display the details of movies whose name ends with letter k

5. Display the details of movies which is not released yet


6. Display the movie name type release date and production cost in
the descending order of production cost
Set 4 – Group by, having and aggregate functions

1. Display the number of movies for each type

2. Display the number of unique movies

3. Display the maximum production cost for each movie type

4. Display the date of movies released latest


5. Display the average business cost of movies for each type

6. Display the type and number of movies for each type where movie
type is more than two
Set 5 – Join Queries

Create two tables as follows and write given queries below:


Table - artist

Table – Song

1. Display the cartesian product of artist and song tables:


2. Display the records of artist and song using equijoin

3. Display the records of artist and song tables using natural join.

4. Display artist name, label and songs of sony music company.

5. Display artist name, song name from artist and song which song
starts with ‘p’
Part C – Python & MySQL Connectivity Programs
Chapter 14 – Interface Python with MySQL

1. Write a program to connect with mysql database and insert a


record into database.
Code:

Output:
2. Write a program to connect with mysql database and update a
record into database.
Code:

Output:
3. Write a program to connect with mysql database and delete a
record into database
Code:

Output:
4. Write a program to connect with mysql database display record of
particular label under the artist is working
Code:

Output:
Part-D Data Structure 2 (Queue and CSV)

Ques 25. Program to create CSV file and store empno, name, salary
and search any empno and display name, salary and if not found
appropriate message

Code:

Output:
Ques 26. Program to implement Queue in Python using list.

Code:
Output:
Ques 27. Program to take 10 sample phishing email and find the most
common word occurring.

Code:

Output:
Ques 28. Program to create 21 Stick Game so that computer always
wins

Code:
Output:

You might also like