0% found this document useful (0 votes)
14 views74 pages

Practical Programs 1

Uploaded by

rajnish052006
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)
14 views74 pages

Practical Programs 1

Uploaded by

rajnish052006
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/ 74

Expt. No …………………… Page No……………….. Date……………………….

PYTHON
PROGRAMS
Expt. No …………………… Page No……………….. Date……………………….

Program 1:
Write a program to check whether a number is palindrome or not.

Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 2:
Write a python program to print Fibonacci series upto n terms, also find sum of series.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 3:
Write a program to generate values from 1 to 10 and then remove all the odd
numbers from the list.

Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 4:
Write a program to find sum of all elements of a list using recursion

Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 5:
Write a program to count frequency of word in a given string/sentence.

Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 6:
Write a random number generator that generates random numbers between
1 and 6 (simulates a dice)

Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 7:
Write a program to count number of words in a text file.

Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Text File:

Output:
Expt. No …………………… Page No……………….. Date……………………….

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

Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Text File:

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 9:
Program to read a text file and display the number of vowels /consonants/ uppercase/
lowercase characters in the file.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Text File:

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 10:
Program to remove all the lines that contain the character ‘a’ in a file and write it to
another file.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Text File:

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 11:
Create a binary file with roll number, name, marks and marks. Search for a given roll
number and display the details of the students, if not found display appropriate
message.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….
Expt. No …………………… Page No……………….. Date……………………….

Program 12:
Create a binary file with roll number, name and marks. Input a roll number and update
the marks.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….
Expt. No …………………… Page No……………….. Date……………………….

Program 13:
Write a menu-based python program to implement a stack using list
(Push, Pop, Display and Exit).
Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….
Expt. No …………………… Page No……………….. Date……………………….

Program 14:
Create a CSV file (data.csv) by entering roll number, name and marks. Then read and
search the marks for given roll number.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….
Expt. No …………………… Page No……………….. Date……………………….

Program 15:
Create a CSV file (detail.csv) by entering roll number, name and marks. Then read from
the csv file (details.csv) of those student’s details who scored more than 75 marks.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 16:
Create a CSV file by entering user-id and password, read and search the password for
given user-id.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

SQL
COMMANDS
Expt. No …………………… Page No……………….. Date……………………….

DATABASE MANAGEMENT-STUDENT TABLE


1. Create Database:
Command:
mysql> create database class12cs;
Output:

2. Use Database:
Command:
mysql> use class12cs;
Output:

3. Create Table:
Command:
mysql> create table Student
-> (Rno int Primary Key,
-> Name varchar(10) NOT NULL,
-> Gender varchar(8),
-> Marks int,
-> Scode varchar(5)
-> );
Output:
Expt. No …………………… Page No……………….. Date……………………….

4. To view the Table Structure:


Command:
mysql> desc Student;
Output:

5. Insert Command:
Command:
mysql>insert into Student value(1,'Neha','Female',100,'S101');
mysql> insert into Student value(2,'Nisha','Female',100,'S101');
mysql> insert into Student value(3,'Pooja','Female',75,'S102');
mysql> insert into Student value(4,'Pankaj','male',42,'S103');
mysql> insert into Student value(5,'Priyanka','Female',72,'S102');
mysql> insert into Student value(6,'Soniya','Female',85,'S101');
mysql> insert into Student value(7,'Soumya','Female',15,'S103');
mysql> insert into Student value(8,'Uttkarsh','male',99,'S101');
mysql> insert into Student value(9,'Ajay','male',98,'S101');
mysql> insert into Student value(10,'Muskan','Female',100,'S102');
mysql> insert into Student value(11,'Satish','male',50,'S103');
Expt. No …………………… Page No……………….. Date……………………….

Output:

6. Select Command:
Command:
mysql> select * from Student;
Expt. No …………………… Page No……………….. Date……………………….

Output:

7. Alter Command (Add Attribute):


Command:
mysql> alter table Student add column(Contact_No varchar(15), Address
varchar(10));
Output:
Expt. No …………………… Page No……………….. Date……………………….

8. Alter command (Drop attribute):


Command:
mysql> alter table Student drop Contact_No;
Output:

9. Alter command (Modify attribute):


Command:
mysql> alter table Student modify Marks decimal;
Output:
Before Modification:
Expt. No …………………… Page No……………….. Date……………………….

After Modification:

10. Update (Adding Data in the new attribute)


1st Command:
mysql> update Student set Address= 'Sector 53';
Output:
Expt. No …………………… Page No……………….. Date……………………….

2nd Command:
mysql> update Student set Address= 'Sector 17' where Scode='S101';
Output:

11. Order By (Ascending and Descending)


1st Command:
mysql> select * from Student order by Name asc;
Output:
Expt. No …………………… Page No……………….. Date……………………….

2nd Command:
mysql> select Name, Marks from Student order by Marks desc;
Output:

12. Delete (Tuple’s):


Before Deletion:
Expt. No …………………… Page No……………….. Date……………………….

After Deletion:
1st Command:
mysql> delete from Student where Rno=6;
Output:

2nd Command:
mysql>delete from Student where Marks<20;
Output:
Expt. No …………………… Page No……………….. Date……………………….

13.Group By:
1st Command:
mysql>select Gender, Count(*) from Student group by Gender;
Output:

2nd Command:
mysql>select Scode, count(*) from Student group by Scode;
Output:

3rd Command:
mysql>select Scode, count(*) from Student group by Scode having
count(*)>2;
Output:
Expt. No …………………… Page No……………….. Date……………………….

14.Min, Max, Sum, Avg and Count


Expt. No …………………… Page No……………….. Date……………………….

DATABASE MANAGEMENT – EMPLOYEE TABLE

Field Name Datatype Constraint


Empid Integer Primary Key
Name Varchar (20) Not Null
Gender Varchar(1)
Age Integer(2)
Department Varchar(20) Not Null
Desig Varchar(10)
Salary Integer
Place Varchar(20)
DOJ Date

1. Create Table
SQL Code:
mysql> create table Employee (
-> Empid Integer Primary Key,
-> Name varchar (20) Not Null,
-> Gender varchar (1),
-> Age Integer (2),
-> Department varchar (20) NOT NULL,
-> Salary Integer,
-> Place varchar (20),
-> DOJ date
-> );
Expt. No …………………… Page No……………….. Date……………………….

Output:

2. Insert the Data:


Command:
mysql> insert into Employee
value(1001,'Aman','M',24,'Accounts','Accountant',35000,'Patna','2015-05-13');
mysql> insert into Employee
value(1002,'Shyam','M',20,'Sales','Manager',55000,'Hyderabad','2010-11-15');
mysql> insert into Employee
value(1003,'Sheela','F',22,'Admin','Officer',50000,'Delhi','2012-07-20');
mysql> insert into Employee
value(1004,'Meera','F',32,'Sales','Officer',60000,'Patna','2020-12-25');
Expt. No …………………… Page No……………….. Date……………………….

mysql> insert into Employee


value(1005,'Manu','M',42,'Accounts','Officer',40000,'Delhi','2014-02-27');
mysql> insert into Employee
value(1006,'Nita','F',28,'Admin','Clerk',25000,'Hyderabad','2009-10-30');
mysql> insert into Employee
value(1007,'Praveen','M',26,'Admin','Manager',70000,'Patna','2022-04-22');
mysql> insert into Employee
value(1008,'Preeti','F',35,'Sales','Accountant',15000,'Hyderabad','2021-08-11');
mysql> insert into Employee
value(1009,'Simran','F',21,'Admin','Accountant',20000,'Delhi','2019-03-18');
mysql> insert into Employee
value(1010,'Ayush','M',25,'Admin','Clerk',30000,'Patna','2007-09-27');
Expt. No …………………… Page No……………….. Date……………………….

3. Select Command:
Command:

4. Alter Command (Add Attribute):


Command:
mysql> alter table Employee add column(Contact_No varchar(15),
Marital_Status varchar(1));
Output:
Expt. No …………………… Page No……………….. Date……………………….

5. Alter command (Drop attribute):


Command:
mysql> alter table Employee drop Marital_Status;
Output:

6. Inserting Contact_No to each employee:


Command:

mysql>update Employee set Contact_No = '6157323650' where Empid=1001;


mysql>update Employee set Contact_No = '6157323670' where Empid =1002;
mysql>update Employee set Contact_No = '6157323680' where Empid =1003;
mysql>update Employee set Contact_No = '6157323690' where Empid =1004;
mysql>update Employee set Contact_No = '6157323700' where Empid =1005;
mysql>update Employee set Contact_No = '6157323710' where Empid =1006;
mysql>update Employee set Contact_No = '6157323720' where Empid =1007;
Expt. No …………………… Page No……………….. Date……………………….

mysql>update Employee set Contact_No = '6157323650' where Empid =1008;


mysql>update Employee set Contact_No = '6157323631' where Empid =1009;
mysql>update Employee set Contact_No = '6157323640' where Empid =1010;
Output:
Expt. No …………………… Page No……………….. Date……………………….

7. Display all the records of Female Employees.


Command:
mysql> Select * from Employee where Gender = 'F';
Output:
Expt. No …………………… Page No……………….. Date……………………….

8. Display the maximum and minimum Salary of Employees.


Command:
mysql> Select max(Salary), min(Salary) from Employee;
Output:

9. Display total number of male Employees.


Command:
mysql> Select count (*) from Employee where Gender = 'M';
Output:

10. Display the detail of Employees who joined in year 2015.


Command:
mysql> Select * from Employee where year (DOJ)=2015;
Output:
Expt. No …………………… Page No……………….. Date……………………….

11. List the employees who joined after 2018/01/01.


Command:
select * from Employee where DOJ > '2018-01-01';
Output:

12. Check for Null value in DOJ of any record.


Command:
select * from Employee where DOJ is null;
Output:
Expt. No …………………… Page No……………….. Date……………………….

13. To Display name of employees in upper case who joined on “Wednesday”.


Command:
mysql> Select upper (Name) from EMPLOYEE where
dayname (DOJ) = "Wednesday";
Output:

14. To Display the salary Department wise.


Command:
mysql> Select sum (Salary), Department from Employee group by
Department;
Output:
Expt. No …………………… Page No……………….. Date……………………….

15.To Display Distinct (place) from Employee.


Command:
mysql> select count(distinct place) from Employee;
Output:

16.To Select * using Where – Like clause


Command:
mysql> select * from Employee where Name like “S%”;
Output:
Expt. No …………………… Page No……………….. Date……………………….

PYTHON – SQL
CONNECTIVITY
PROGRAMS
Expt. No …………………… Page No……………….. Date……………………….

Program 1:
Program to connect with database and store record of employee and display records
Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 2:
Program to connect with database and search employee number in table employee
and display record, if empno not found display appropriate message.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 3:
Program to connect with database and update the employee record of entered empno.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….
Expt. No …………………… Page No……………….. Date……………………….

Output:
Expt. No …………………… Page No……………….. Date……………………….

Program 4:
Program to connect with database and delete the record of entered employee number.
Program Code:
Expt. No …………………… Page No……………….. Date……………………….

Output:

You might also like