PG1- Removing Repeated Elements from a List
Write a Python Program to remove repeated elements from a list.
Source Code
Result:
Thus the program was executed successfully and output is verified.
4
PG2- Dictionary Creation
Write a Python Program to create a dictionary containing names of competition
winner students as keys and number of their wins as values.
Source Code
Result:
Thus the program was executed successfully and output is verified.
5
PG3 – Reverse & Swapping List
Write a Python Program to accept 5 items into a list and reverse the list. Also
swap the first and last items in the list.
Source Code
Result:
Thus the program was executed successfully and output is verified.
6
PG4 – String Palindrome
Write a Python Program to check if a string is palindrome or not.
Source Code
Result:
Thus the program was executed successfully and output is verified.
7
PG5 – Check a Value Exists in Dictionary
Write a Python Program to check whether a value exists in dictionary.
Source Code
Result:
Thus the program was executed successfully and output is verified.
8
PG6 – Factorial
Write a Python Program to calculate a factorial value by given number.
Source Code
Result:
Thus the program was executed successfully and output is verified.
9
PG7 – Arithmetic Operations
Write a Python Program to receives two numbers in a function and returns
the results of all arithmetic operations(+,-,*,/,%) on these numbers.
Source Code
Result:
Thus the program was executed successfully and output is verified.
10
PG8 – Copying Prime Numbers to the List
Write the definition of a method/function Copy_Prime(lst) to copy all the prime
numbers from the list Lst to another list Lst_prime.
Source Code
Result:
Thus the program was executed successfully and output is verified.
11
PG9 – Swapping Odd and Even Position from List
Write a Python function SwitchOver(Val) to swap the even and odd positions of
the values in the list Val.
Note : Assuming that the list has even number of values in it.
For example :If the list Numbers contain
[25,17,19,13,12,15]
After swapping the list content should be displayed as
[17,25,13,19,15,12]
Source Code
Result:
Thus the program was executed successfully and output is verified.
12
PG10 – Displaying words separated by # -Text File
Write a Python Program to read a text file line by line and display each word
separated by '#'.
Source Code
Result:
Thus the program was executed successfully and output is verified.
13
PG19 – CREATE, ALTER, UPDATE Table Using MySQL
Consider the Student Mark sheet as follows:
Table Name: Student
Column Name ID Name Grade PT1 PT2
Data type String of 9 letters Characters 2 characters Number Number
Constraints Primary Key Cannot be Null
CC10356 Arnav 12 65 76
CF10345 Bharathi 11 94 95
Values IM12546 Chandru 12 67 57
IL20056 Dithya 11 54 53
IK13652 Feroz 12 76 65
Write SQL Command for the following Queries with regards to the created table:
(1) Create a Table with the given constraints
(2) Insert the given values to the created table
(3) Create a Column called “Total” with Integer data type
(4) Assign values to the column Total by adding the marks of PTI and PT2
(5) Display the names of the students who got more than 140 marks in total.
(6) Display the details of the student’s grade 12 only.
(1) Creating Table with the given Constraints
Query: CREATE TABLE Student (ID CHAR(9) PRIMARY KEY, Name
VARCHAR(30) NOT NULL, Grade CHAR(2), PT1 INTEGER, PT2 INTEGER);
(2) Insert the given values to the created table
Query: INSERT INTO Student VALUES ('CC10356','Arnav','12',65,76),
('CF10345','Bharathi','11',94,95),('IM12546','Chandru','12',67,57),('IL20056','Dithya','11',
54,53),('IK13652','Feroz','12',76,65);
22
(3) Create a Column called “Total” with Integer data type
Query: ALTER TABLE Student ADD COLUMN Total INTEGER;
(4) Assign values to the column Total by adding the marks of PTI and PT2
Query: UPDATE Student SET Total = PT1+PT2;
(5) Display the names of the students who got more than 140 marks in total.
Query: SELECT Name FROM Student WHERE Total>140;
(6) Display the details of the students grade 12 only.
Query: SELECT * FROM Student WHERE Grade= ‘12’;
Result:
Thus the program was executed successfully and output is verified.
23
PG20 – SELECT, ORDER BY, DELETE Data Using MySQL
Consider the Student Mark sheet as follows:
Table Name: Employee
Column Name EmpNo EmpName Dept Salary Designation
Data type Integer Characters Characters Number Characters
Constraints Primary Key Cannot be Null
150 Arnav Marketing 45000 Executive
134 Bharathi Sales 35000 Executive
Values 167 Chandru Marketing 38500 Asst Manager
195 Dithya Null 37000 Manager
208 Feroz Sales 60000 Manager
Write SQL Command for the following Queries with regards to the created table:
1. Create a Table with the given constraints and Insert the given values to the created
table.
2. Display the details of Employees in ascender order of EmpNo.
3. Display all the department names without repetition.
4. Display the total Department’s in the table.
5. Display the number of Departments in Employee table.
6. To delete the employee record having EmpName as Dithya.
(1) Create a Table with the given constraints and Insert the given values to the created
table.
Query: CREATE TABLE Employee (EmpNo INT PRIMARY KEY, EmpName
VARCHAR(30) NOT NULL, Dept VARCHAR(30), Salary INT, Designation
VARCHAR(30));
INSERT INTO Employee VALUES (150,'Arnav','Marketing',45000,'Executive'),
(134,'Bharathi','Sales',35000,'Executive'), (167,'Chandru','Marketing',38500,'Ast
Manager'), (195,'Dithya','HR',37000,'Manager'), (208,'Feroz','Sales',60000,'Manager');
24
(2) Display the details of Employees in ascender order of EmpNo.
Query: SELECT * FROM Employee ORDER BY EmpName;
(3) Display all the department names without repetition.
Query: SELECT DISTINCT (Dept) FROM Employee;
(4) Display the number of records in the table.
Query: SELECT COUNT(*) FROM Employee;
(5) Display the number of Departments in Employee table.
Query: SELECT COUNT(Dept) FROM Employee;
(6)To delete the employee record having EmpName as Dithya.
Query: DELETE FROM Employee WHERE EmpName= ‘Dithya’;
Result:
Thus the program was executed successfully and output is verified.
25
PG21 – Aggregate Function, Group By Data Using MySQL
Consider the Student Mark sheet as follows:
Table Name: COMPUTER
Column Name PROD_ID PROD_NAME PRICE COMPANY TYPE
Data type Characters Characters Integer Characters Characters
Constraints Primary Key Canonot be Null
P001 MOUSE 200 LOGITECH INPUT
P002 LASER PRINTER 4000 CANON OUTPUT
Values P003 KEYBOARD 500 LOGITECH INPUT
P004 JOYSTICK 1000 IBALL INPUT
P005 SPEAKER 1200 CREATIVE OUTPUT
Write SQL Command for the following Queries with regards to the created table:
1. Create a Table with the given constraints and Insert the given values to the created
table.
2. Display the details of Maximum and Minimum price of products.
3. Display all the count of the product each type.
4. Display the total price of the product each company wise.
5. Display the difference of highest and lowest salary of each company having
maximum price>1000.
6. To delete the attribute Type in Computer Table.
(1) Create a Table with the given constraints and Insert the given values to the created
table.
Query: CREATE TABLE COMPUTER(PROD_ID VARCHAR(30) PRIMARY KEY,
PROD_NAME VARCHAR(30) NOT NULL, PRICE INT, COMPANY VARCHAR(20),
TYPE VARCHAR (20));
26
INSERT INTO COMPUTER VALUES ('P001','MOUSE',200,'LOGITECH','INPUT'),
('P002','LASER PRINTER',4000,'CANON','OUTPUT'),
('P003','KEYBOARD',500,'LOGITECH','INPUT'),
('P004','JOYSTICK',1000,'IBALL','INPUT'),('P005','SPEAKER',1200,'CREATIVE','OUT
PUT'),('P006','DESKJET PRINTER',4300,'CANON','OUTPUT');
(2) Display the details of Maximum and Minimum price of products.
Query: SELECT MAX(PRICE),MIN(PRICE) FROM COMPUTER;
(3) Display all the count of the product each type.
Query: SELECT COUNT(*) FROM COMPUTER GROUP BY TYPE;
(4) Display the total price of the product each company wise.
Query: SELECT SUM(PRICE),COMPANY FROM COMPUTER GROUP BY
COMPANY;
(5) Display the difference of highest and lowest salary of each company having maximum
price>1000.
Query: SELECT MAX(PRICE)-MIN(PRICE) “DIFFERENCE” FROM COMPUTER
GROUP BY COMPANY HAVING MAX(PRICE)>1000;
27
(6) To delete the attribute Type in Computer Table.
Query: ALTER TABLE COMPUTER DROP COLUMN TYPE;
Result:
Thus the program was executed successfully and output is verified.
28
PG22 – Displaying Data(SELECT) Using Python With MySQL
To write a code in Python to display all the details of the passengers from the
table flight in MySQL database, Travel. The table contains the following
attributes:
F_ code : Flight code (String)
F_name: Name of flight (String)
Source: Departure city of flight (String)
Destination: Destination city of flight (String)
Consider the following to establish connectivity between Python and MySQL:
● Username : root
● Password : airplane
● Host : localhost
Table Name: FLIGHT
F_code F_Name Source Destination
F101 Indigo Delhi Chennai
F102 Etihad Delhi Bengaluru
F103 Qatar Airways Mumbai Chennai
F104 Kingfisher Delhi Mumbai
F105 Emirates Mumbai Bengaluru
Source Code
29
F_code F_Name Source Destination
F101 Indigo Delhi Chennai
F102 Etihad Delhi Bengaluru
F103 Qatar Airways Mumbai Chennai
F104 Kingfisher Delhi Mumbai
F105 Emirates Mumbai Bengaluru
Result:
Thus the program was executed successfully and output is verified.
30