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

Practical File(2023-2024)

Index
Program Number Title
Program-1 Basics of Python-Phishing E-Mail
Program-2 Functions- Printing Factorial/Fibonacci/Prime Number
Program-3 Built in Module-Using Statistics/Random module
Program-4 Text File-1- Manipulating lines
Program-5 Text File-2 -Analysing characters
Program-6 Text File-3 – Manipulating words
Program-7 Binary File-1 – Inserting, Displaying and Searching with list
Program-8 Binary File-2 - Inserting, Displaying and Deleting with list
Program-9 Binary File-3 - Inserting, Displaying and Updating with
Dictionary
Program-10 CSV File-1 – Inserting, Displaying and Updating with list
Program-11 CSV File-2 - Inserting, Deleting and displaying with list
Program-12 CSV File-3 - Inserting, Searching and Displaying with List
Program-13 Stack-1-Push, Pop and Display with list
Program-14 Stack-2-Push and Peek with list
Program-15 Stack-3- Push, count of stk_ele and Display with dictionary
Program-16 PYTHON-SQL CONNECTIVITY-1
Program-17 PYTHON-SQL CONNECTIVITY-2
Program-18 PYTHON-SQL CONNECTIVITY-3
Program-19 PYTHON-SQL CONNECTIVITY-4
Program-20 PYTHON-SQL CONNECTIVITY-5
Program-21 PYTHON-SQL CONNECTIVITY-6

Class XII - Computer Science with Python(083)

Note:
Write the Title, Question, Aim ,Code and Result on the R.H.S.(with blue ink) of your
observation notebook & record note book, the output alone on the L.H.S.(will be given
later).Open the link of Python program in laptop or desktop to see the code. Start every
exercise on a fresh page

1
Program 1:
Title: Basics of Python-Phishing E-Mail
Question: Write a Program to take 10 sample phishing emails and find the most common
occurring domain.
AIM: To write a Program to take 10 sample phishing emails and find the most common
occurring domain.
CODE:
https://drive.google.com/file/d/1u0lcPxuHzW5spMlcLSkKaBx8iCXXBj2z/view?usp=share_link
Result: The above program is executed successfully and the output is verified

2
Program 2:
Title: Functions- Printing Factorial/Fibonacci/Prime Number
Question: Write a program to calculate the factorial value or to print the Fibonacci series for
n terms or check whether the entered no. is prime or not based on users’ choice.
AIM:
To write a menu driven program
1. to calculate the factorial value
2. to print the Fibonacci series for n terms
3. to check whether the entered no. is prime or not.

CODE: https://drive.google.com/file/d/1RKBVdA1fstjSQlhb2um5UkGbhzezPFWY/view?
usp=share_link

Result: The above program is executed successfully and the output is verified

3
Program:3
Title: Built in Module-Using Statistics/Random module
Question: Write a Program to use the functions from Statistics and Random modules.
Aim: To write a menu – driven program to import and use the below modules.
1.Statistics
2.Random
CODE:
https://drive.google.com/file/d/1vfR7DkXCG9-g9hP3SlPHdUiCYlffNDXP/view?usp=share_link

Result: The above program is executed successfully and the output is verified

4
Program 4 :
Title: Text File-1- Manipulating lines
Question: Write a text file handling program in python to do the following
1. To read a text file line by line and display each word separated by a #.
2. To remove all the lines that contain the character `W’ from a file and write it to another
file

AIM: To write a menu – driven program to perform the following on a text file
1. To write a python function to read a text file line by line and display each word
separated by a #.
2. To write a python function to remove all the lines that contain the character `W’
from a file and write it to another file
CODE:
https://drive.google.com/file/d/16Yr-e-l8_785RP6rlcpSl9hzAFlkfQTE/view?usp=share_link

Result: The above program is executed successfully and the output is verified

5
Program 5:
Title : Text File-2 -Analysing characters
Question: Write a text file handling program in python to do the following
1. Display the number of vowels
2. Display the number of consonants
3. Display the number of upper-case characters
4. Display the number of lower-case characters

AIM:
To write a menu – driven program to perform the following on a text file
1. Display the number of vowels
2. Display the number of consonants
3. Display the number of upper-case characters
4. Display the number of lower-case characters
CODE:
https://drive.google.com/file/d/1TPPNBwqYgQO5HBqLfl6LsQzoy6nLsHDN/view?usp=share_link

Result: The above program is executed successfully and the output is verified

6
Program 6:
Title: Text File-3 – Manipulating words
Question: Write a text file handling program in python to do the following
1. Counting the specific word in a file
2. Replace the given word with another word
3. Display the words ending with character 'e'
4. Display the longest word of the file

AIM:
To write a menu – driven program to perform the following on a text file
1. Counting the specific word in a file
2. Display the text after replacing the given word with another word
3. Display the words ending with character 'e'
4. Display the longest word of the file
CODE:
https://drive.google.com/file/d/18RF9KkhkCVzGRLuB2qyiEkI2LYjzS1_q/view?usp=share_link

Result: The above program is executed successfully and the output is verified

7
Program 7:
Title: Binary File-1 – Inserting, Displaying and Searching with list
Question: Write a Program to create a product record on a binary file.
AIM: To write a python
1.Insert record
2.Display record
3.Search record
4.Exit
CODE:
https://drive.google.com/file/d/1ZMM3S_5Y1AF5xNpt_io_I_Bu96hxsqil/view?usp=share_link

Result: The above program is executed successfully and the output is verified

8
Program 8:
Title : Binary File-2 - Inserting, Displaying and Deleting with list
Question: Write a Program to Create a Employee Record on a Binary File.
AIM:
To write a menu – driven program to perform the following tasks on a Binary file
1.Insert record
2.Display record
3.Delete record
4.Exit
CODE:
https://drive.google.com/file/d/1mCEZhqjz9I28ZuHCWP2Q2pIZsyvPz-X2/view?usp=share_link

Result: The above program is executed successfully and the output is verified

9
Program 9:
Title : Binary File-3 - Inserting, Displaying and Updating with Dictionary
Question: Write a Program to Create a Student Record on a Binary File.
AIM:
To write a menu – driven program to perform the following tasks on a Binary file
1.Enter data
2.Display data
3.Update data
4.Exit
CODE:
https://drive.google.com/file/d/1d5K2-3nmhmfxGZPA7nPFsznLMlwLHf-W/view?usp=share_link

Result: The above program is executed successfully and the output is verified

10
Program -10:
Title : CSV File-1 – Inserting, Displaying and Updating with list
Question: Write a Program to Create a Customer record with CSV file.
AIM:
To write a menu – driven program to perform the following tasks on a CSV file
1-Add record
2-Display records
3-Modify record
4-Exit
CODE:
https://drive.google.com/file/d/16m2LVWzE5ydfAKq-dzjFkJ0S2UN_LFlo/view?usp=share_link

Result: The above program is executed successfully and the output is verified

11
Program -11:
Title : CSV File-2 - Inserting, Deleting and displaying with list

Question: Write a Program to Create a Book Details Record using CSV file.
AIM:
To write a menu – driven program to perform the following tasks on a CSV file
1. Add New Book
2. Display Books in sorted order
3. Delete Book
4. Quit
CODE:
https://drive.google.com/file/d/1mX-9jgIN5u46OhARZKEjtyRX0ElFV-i_/view?usp=share_link

Result: The above program is executed successfully and the output is verified

12
Program -12:
Title : CSV File-3 - Inserting, Searching and Displaying with List

Question: Write a Program to Create a record of user credentials using CSV file.
AIM:
To write a menu – driven program to perform the following tasks on a CSV file
1: Create
2: Search
3: Display
4: Exit
CODE:
https://drive.google.com/file/d/1E2AKA0kH28ArcKh5ef6rZF6QLFTo5bfl/view?usp=share_link

Result: The above program is executed successfully and the output is verified

Program -13:

13
Title : Stack-1-Push, Pop and Display with list
Question: Write a Program to Create and perform all basic operations of Stack with list of
numbers
AIM:
To write a menu – driven program to perform the following tasks on a number Stack.
STACK OPERATIONS
1: PUSH the elements divisible by 5
2: POP
3: Display
4: Exit
CODE:
https://drive.google.com/file/d/1mHBwxCgOxBEI_SppfNHjH4t3BHoKC7Gz/view?usp=share_link

Result: The above program is executed successfully and the output is verified

Program -14:
14
Title : Stack-2-Push and Peek with list
Question: Write a Program to Create and perform all basic operations of Stack with
customer details
AIM:
To write a menu – driven program to perform the following tasks on a
Customer[Customer_name, Phone_number, City] Stack
1: PUSH - The customer details based on city
2: PEEK
3: EXIT
CODE:
https://drive.google.com/file/d/1D5PNGSHzTJ8j6sn2Wmx4dR6IZbcKqzq5/view?usp=share_link

Result: The above program is executed successfully and the output is verified

Program -15:

15
Title : Stack-3- Push, count of stk_ele and Display with dictionary
Question: Write a Program to Create and perform all basic operations of Stack with
dictionary {pname:price}
AIM:
To write a menu – driven program to perform the following tasks on a product Stack
STACK OPERATIONS
1: PUSH Product names with price > 75
2: Count the no. of elements in stack
3: Display
4: Exit
CODE:
https://drive.google.com/file/d/1zpQ197lynswzZmiyUW2VmohYuWSuP_fc/view?usp=share_link

Result: The above program is executed successfully and the output is verified

Program -16
16
Title: PYTHON-SQL CONNECTIVITY-1
Question :Write a menu driven program to perform the following task on “XII”
database:
i) Creating the following table “CARDEN”
ii) Inserting the given records
Ccode CarName Make Color Capacity Charges
501 A-Star Suzuki RED 3 14
503 Indigo Tata SILVER 3 12
502 Innova Toyota WHITE 7 15
509 SX4 Suzuki SILVER 4 14
510 C Class Mercedes RED 4 35

iii) Query 1: To display the names of all the silver-coloured Cars


iv) Query 2 :To increase charges by 10 where capacity is greater than 3
v) Query 3 :To display the CarName ,Capacity in descending order of capacity

AIM :
To write a menu driven program to perform the following task on “XII” database .
CODE:

https://drive.google.com/file/d/14efirkjCzbdSDqgtyCL_d-v80id5CXf4/view?usp=share_link

Result: The above program is executed successfully and the output is verified

Program -17
Title: PYTHON-SQL CONNECTIVITY-2

17
Question : Write a menu driven program to perform the following task on “XII”
database:
i) Creating the following table “SPORTS”
ii) Inserting the given records
Stud_no Class name game1 grade1
10 7 Sameer Cricket B
11 8 Sujith Tennis A
12 7 Kamal Swimming B
13 7 Venna Tennis C
14 9 Archana Basketball A
15 10 Arpit Cricket A
iii) Query 1: To display the name of students with game as swimming
iv) Query 2: To delete the rows where class is 10
v) Query 3: To display the number of students from each class.
AIM:
To write a menu driven program to perform the following task on “XII” database.
CODE:
https://drive.google.com/file/d/1J3gZYbCsnRoqfRu3rPUOrx2oGvLtatV0/view?usp=share_link

Result: The above program is executed successfully and the output is verified

Program -18

18
Title:PYTHON-SQL CONNECTIVITY-3

Question : Write a menu driven program to perform the following task on “XII”
database:
i) Creating the following table “ORDERS”
ii) Inserting the given records
OderID Pname Quantity Rate Sale_date Discount
1001 Pen 10 20 2019-10-05 NULL
1002 Pencil 20 10 2019-10-21 NULL
1003 Book 10 100 2019-11-12 50
1004 Eraser 100 5 2019-12-05 25
1005 Copy 50 20 2019-12-10 NULL
iii) Query1:To display Pname, Quantity and Rate for all the orders that are either pen
or pencil
iv)Query2:To display orders which are not getting any discount
v) Query3: Update Rate by 5%.
AIM:
To write a menu driven program to perform the following task on “XII” database

CODE:

https://drive.google.com/file/d/17FAgVmcy7dPOH5U5pSHou0dS7kjVeUnr/view?usp=share_link

Result: The above program is executed successfully and the output is verified

19
Program -19
Title:PYTHON-SQL CONNECTIVITY-4

Question : To write a menu driven program to perform the following task on “XII”
database:
i) Creating the following table “STUDENT”
ii) Inserting the given records

iii) Query 1: To display the records from table student in alphabetical order as per the
name of the student.
iv) Query 4: To display Class, Dob and City whose marks is between 450 and 551.
v) Query 5: To display the highest marks
AIM:
To write a menu driven program to perform the following task on “XII” database:

CODE:

https://drive.google.com/file/d/15NGjO7k8_1rzGB8LIKALB28XYY9BGEuL/view?usp=share_link

Result: The above program is executed successfully and the output is verified

20
Program -20
Title:PYTHON-SQL CONNECTIVITY-5

Question :Write a menu driven program to perform the following task on “XII” database:
i) Creating the following table “EMPLOYEE”
ii) Inserting the given records
Fcode Fname Sex Salary Subject JoinDate
F1001 Hari Charan M 101000 English 2000-10-11
F1004 Mallika F 202000 Programming 2003-11-30
F1002 Arun M 202000 Web design 2001-09-06
F1005 Priya F 201000 Web design 2004-12-15
F1009 Tanya F 203000 Programming 2006-12-31
F1006 Amar M 108000 Data structure 2005-05-02
F1008 Avinash M 105000 Maths 2002-03-15
iii) Query 1: To display Fcode, Fname, JoinDate, Salary of all faculty members in
descending order of their salary.
iv) Query 2: To increase the salary of all faculties by 2000, who are either teaching the
subject “Programming” or teaching the subject “Maths”.
v) Query 3: To display details of all faculty whose name ends with letter “n”.
AIM:
To write a menu driven program to perform the following task on “XII” database:

CODE:

https://drive.google.com/file/d/1eSE1Y6L8Ty7dZtrIjYiv52O6TN0Bx-ef/view?usp=share_link

Result: The above program is executed successfully and the output is verified

21
Program -21
Title:PYTHON-SQL CONNECTIVITY-6

Question : Write a menu driven program to perform the following task on “XII”
database:
i) Creating the following table “ITEMS”
ii) Inserting the given records
ItemNo Name Dcode Qty UnitPrice StockDate
5005 CD 101 100 25 2010-03-31
5003 Floppy 101 150 10 2010-01-01
5002 Pendrive 101 125 200 2010-02-14
5006 Mouse 102 200 300 2009-03-19
5001 Keyboard 102 60 400 2009-12-19
iii) Query1: Display the Item name with stockdate in the year 2010.
iv) Query2: To display the ItemNo and name of those items from the above table whose
Unitprice is more than Rs10.
v) Query 3: To display the total Qty of each Dcode.
AIM:
To write a menu driven program to perform the following task on “XII” database

CODE:

https://drive.google.com/file/d/1XxuP6wGMBYNGRt9oY468B6YzzaAYMeCM/view?usp=share_link

Result: The above program is executed successfully and the output is verified

Database Commands in MySql


1. To get list of available databases:
mysql>SHOW DATABASES;
22
2.To create a database:
mysql>CREATE database myschool;

3. To delete a database:
mysql>DROP database <databasename>;

4. To open the database:


mysql>USE myschool;

5. To remove table:
mysql>droptable <tablename>;
6. To show list of tables in opened database:
mysql>SHOW TABLES;

7. To create a table in the database.


mysql>CREATE TABLE student(lastname varchar(15),firstname varchar(15),city
varchar(20),class char(2));

8. To view the structure of a table.


mysql>DESCRIBE student;

9. To create a table with Constraints


mysql>CREATE TABLE Persons(IDint NOT NULL PRIMARYKEY,
LastName varchar(255) NOT NULL, FirstName varchar(255),
Age int, City varchar(255) DEFAULT ‘Jaipur', CONSTRAINT CHK_Person
CHECK(Age>=18));
mysql>CREATE TABLE Orders(OrderID int NOT NULL, OrderNumber int NOT NULL,
PersonID int, PRIMARY KEY(OrderID),FOREIGN KEY(PersonID) REFERENCES
PERSONS(ID);

10. To insert new rows into an existing table:


mysql>INSERT INTO student values(‘dwivedi’,’freya’,’Udaipur’,’4’);

11. To insert record with specific column only:


mysql>INSERT INTO student(lastname,firstname,city) values(‘dwivedi’,’Mohak’,’Udaipur’,);

12. To select all the fields of a table:


mysql>SELECT*FROM student;
23
13. To select rows by using the WHERE:
mysql>SELECT * FROM student WHERE class=“4";

14. To select specific columns(Projection)by listing their names:


mysql>SELECT first_name,class FROM student;

15. To select rows with null values in specific column:


mysql>SELECT*FROM Student WHERE City IS NULL;

16. To select rows BETWEEN the given values in specific column:


mysql>SELECT * FROM Student WHERE class between 4and6;

17. To select rows with given list of values in specific column:


mysql>SELECT*FROM Student WHERE class in(4,5,6);

18. To select rows using LIKE operator:


mysql>SELECT* FROM Student WHERE Name LIKE ‘A%’;
mysql>SELECT * FROM Student WHERE Name LIKE ’%Singh%’;

19. To select rows using Like operator with relational and logical operator:
mysql>SELECT Name,City FROM Student WHERE Class>=8 AND Name LIKE ‘%Kumar%’;

20. To display data after removal of duplicate values from specific column:
mysql>select distinct class from student;

21. To delete selected rows from a table:


mysql>DELETE FROM student WHERE firstname=“amar";

22. To modify or update entries in the table:


mysql>UPDATE student SET class=“V" WHERE firstname=“freya";
24
23. To add a New Column inan existing tabl:
msql>ALTER TABLE ADD column_name datatype;

24. To drop column in an existing table:


mysql>ALTER TABLE student DROP marks;

25. To change the DATATYPE of a column in a table:


mysql>ALTER TABLE student change name name varchar(30);
mysql>ALTER TABLE student modify(name varchar(30));

26. To add a NOT NULL constraint to a column:


mysql>ALTER TABLE student MODIFY name varchar(30) NOTNULL;

27. To add UNIQUE CONSTRAINT to a column:


mysql>ALTER TABLE student ADD CONSTRAINT MyUnique Constraint
UNIQUE(name,address);

28. To ADD CHECK CONSTRAINT to a table:


mysql>ALTER TABLE student ADD CONSTRAINT MyUnique Constraint CHECK(marks>=0);

29. To ADD PRIMARY KEY constraint to a table:


mysql>ALTER TABLE student ADD CONSTRAINT My Primary Key PRIMARY
KEY(first_name,last_name);

30. To DROP CONSTRAINT from a table:


mysql>ALTER TABLE student DROP CONSTRAINT MyUnique Constraint;

31. To DROP PRIMARY KEY constraint from a table


mysql>ALTER TABLE student DROP CONSTRAINT MyPrimaryKey;
mysql>ALTER TABLE student DROP PRIMARY KEY;

25
32. To display the records in ascending order.
mysql>select * from student order by class;
mysql>select*from student order by class asc;

33. To display the records in descending order.


mysql>select*from student order by class desc;

34. To order the data on multiple columns:


mysql>select * from student order by class asc, marks asc;
mysql>select * from student order by class asc, marks desc;

35. To order the data on the basis of an expression:


mysql>select name,mark from student where marks>80 order by class;

36. To sort the data in specific order:


mysql>select*from student order by FIELD(city,’Chennai’,’Mumbai’,’Delhi’);

37. To apply Aggregate functions:


mysql>select Sum(Sal) from EMP;
mysql>select Sum(Sal) from EMP where grade=”E2”;
mysql>Select Min(Sal) from EMP;
mysql>Select Min(Sal) from EMP where(gradE=”E1”orgrade=”E2”);
mysql>Select Max(Sal) from EMP;
mysql>Select Count(Sal) from EMP;
mysql>Select Avg(Sal) from EMP;
mysql>Select Count(*) from Emp;

38. To group the records by column name:


msql>select class from student group by class;

26
39. To group the records by column name with aggregate functions:
mysql>select class,count(*) from student group by class;
mysql>select class,avg(marks) from student group by class;

40. To group the records by column with aggregate functions (with where and order by clause):
mysql>select class,avg(marks) from student where class<10 group by class order by marks
desc;

41. To order the records after grouping by specific column:


mysql>select class,avg(marks) from student where class<10 group by class order by marks
desc;

42. To group there cords with aggregate functions & having clause:
mysql>select class,avg(marks) from student group by class having avg(marks)<90;
mysql>select class,avg(marks) from student group by class having count(*)<3;

43. To display Cartesian product(X)/cross joint:


mysql>Select* from a,b;
mysql>Select*from a cross join b;

44. To display the records using INNER Join or EQUI Join ⋈


mysql>Select course.student_name from couse,student where
course.student_name=student.student_name;
mysql>Select a.name from a inner join b on a.name=b.name;

45. To display the records using Natural JOIN(⋈)


mysql>Select*from a natural join b;

46. To display the records using LEFT Outer Join :


mysql>Select* from a left outer join b on(a.name=b.name);

47. To display the records using RIGHT Outer Join:


27
mysql>Select*from a right outer join b on(a.name=b.name);

48. To display the records using Full Outer Join:


mysql>Select*from a left outer join b on(a.name=b.name) union Select * from a right outer join
b on (a,name=b.name);

28

You might also like