12 CS EM Kalviexpress Practical Hand Book
12 CS EM Kalviexpress Practical Hand Book
12 CS EM Kalviexpress Practical Hand Book
in
in
a) CALCULATE FACTORIAL
1 PY1
2. In Practical exams, the question paper will have two questions with internal b) SUM OF SERIES
s.
a) ODD OR EVEN
choice. 2 PY2
b) REVERSE THE STRING
es
3. One question should be chosen from the list of internal choice
3 PY3 GENERATE VALUES AND REMOVE ODD NUMBERS
4. Distribution of Marks as follows
pr
Duration of Practical: 3 Hrs Maximum Marks: 20 4 PY4 GENERATE PRIME NUMBERS AND SET OPERATIONS
I. Internal Assessment: 5 Marks
5 PY5 DISPLAY A STRING ELEMENTS – USING CLASS
ex
Record Book 5 Marks
II. External Assessment: 15 Marks 6 DB6 MYSQL – EMPLOYEE TABLE
vi
(a) C++ Program coding 10 Marks
7 DB7 MYSQL – STUDENT TABLE
al
(b) Execution & Output 5 Marks
8 PY8 PYTHON WITH CSV
Total 20 Marks
.k
9 PY9 PYTHON WITH SQL
w
Prepared by,
w
Parkunan T
PG Asst. in Computer Science,
MHSS, Chengam,
Tiruvannamalai Dt
Cell : 9655 966 906
Mail :[email protected]
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
To write a program for calculating the factorial of the given number using
for loop.
CODING:
in
num = int(input("Enter a number:"))
s.
if(num==0):
fact=1
es
fact=1
for i in range(1,num+1):
pr
fact=fact*i
ex
print("Factorial of" , num," is ",fact)
vi
al
.k
w
w
w
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
SAMPLE OUTPUT:
Enter a number:5
Factorial of 5 is 120
in
s.
es
pr
ex
vi
al
.k
w
w
w
RESULT:
Thus, the program for calculating factorial of given number using for loop
has been created and executed successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
AIM:
To write a program to sum the series: 1/1 + 22/2 + 33/3 + … + nn/n.
in
CODING:
s.
n=int(input("Enter a value of n: "))
es
s=0.0
for i in range(1,n+1):
pr
a=float(i**i)/i
ex
s=s+a
vi
print ("The sum of the series is ", s)
al
.k
w
w
w
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
SAMPLE OUTPUT:
Enter a value of n: 4
The sum of the series is 76.0
in
s.
es
pr
ex
vi
al
.k
w
w
RESULT:
w
Thus, the program for sum of series has been created and executed
successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
CODING:
def oddeven(a):
s.
if(a%2==0):
es
return 1
else:
pr
return 0
num = int (input("Enter a number: "))
ex
if(oddeven(num)==1):
vi
print("The given number is Even")
elif(oddeven(num)==0):
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
SAMPLE OUTPUT 1:
Enter a number: 5
The given number is Odd
SAMPLE OUTPUT 2:
in
Enter a number: 6
s.
The given number is Even
es
pr
ex
vi
al
.k
w
w
w
RESULT:
Thus, the program using functions for checking whether a number is odd
or even has been created and executed successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
CODING:
in
def rev(str1):
str2=''
s.
i=len(str1) - 1
es
while i>=0:
str2+=str1[i]
pr
i-=1
return str2
ex
word=input("\n Enter a String: ")
print("\n The mirror image of the given string is:" , rev(word))
vi
al
.k
w
w
w
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
SAMPLE OUTPUT:
in
s.
es
pr
ex
vi
al
.k
w
w
w
RESULT:
Thus, the program Reverse the string has been created and executed
successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
QUESTION:
3. GENERATE VALUES AND REMOVE ODD NUMBERS
Write a program to generate values from 1 to 10 and then remove
all the odd numbers from the list. AIM:
To write a program for generating values from 1 to 10 and then
removing all the odd numbers from the list.
in
CODING:
s.
num=[]
es
for i in range(1,11):
num.append(i)
pr
print("Numbers from 1 to 10...\n ", num)
for j,i in enumerate(num):
ex
if(i%2==1):
del num[j]
vi
print("The values after removed odd numbers...\n", num)
al
.k
w
w
w
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
SAMPLE OUTPUT:
in
s.
es
pr
ex
vi
al
.k
w
w
w
RESULT:
Thus, the program for generating values from 1 to 10 and then removing
all odd numbers from the list has been created and executed successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
CODING:
in
odd=set([x*2+1 for x in range(0,5)])
s.
primes=set()
for i in range(2,10):
es
for num in range(0,11):
if num>1:
pr
for i in range(2,num):
if(num % i) == 0:
ex
break
vi
else:
primes.add(num)
al print("Odd: ",odd)
.k
print("Prime: ",primes)
print("Union: ",odd.union(primes))
w
print("Intersection: ",odd.intersection(primes))
w
print("Difference: ",odd.difference(primes))
w
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
SAMPLE OUTPUT :
Odd: {1, 3, 5, 7, 9}
Prime: {2, 3, 5, 7}
Union: {1, 2, 3, 5, 7, 9}
in
Intersection: {3, 5, 7}
Difference: {1, 9}
s.
Symmetric Difference: {1, 2, 9}
es
pr
ex
vi
al
.k
w
w
w
RESULT:
Thus, the program for generating a set of prime numbers and odd
numbers and displaying the result of set operations has been created and
executed successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
using Class.
s.
CODING:
class String:
es
def __init__(self):
self.uppercase=0
pr
self.lowercase=0
self.vowels=0
self.consonents=0
ex
self.spaces=0
self.string=""
vi
def getstr(self):
self.string=str(input("Enter a String: "))
al def count_upper(self):
for ch in self.string:
.k
if(ch.isupper()):
self.uppercase+=1
w
def count_lower(self):
w
for ch in self.string:
if(ch.islower()):
w
self.lowercase+=1
def count_vowels(self):
for ch in self.string:
if(ch in ('A','a','e','E','I','i','O','o','u','U')):
self.vowels+=1
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
9 consonants if(ch==" "):
1 Spaces self.spaces+=1
s.
def execute(self):
self.count_upper()
es
self.count_lower()
self.count_vowels()
pr
self.count_consonents()
self.count_spaces()
def display(self):
ex
print("The given String contains...")
print("%d Uppercase"%self.uppercase)
vi
print("%d Lowercase"%self.lowercase)
print("%d vowels"%self.vowels)
al print("%d consonants"%self.consonents)
print("%d Spaces"%self.spaces)
.k
S=String()
S.getstr()
w
S.execute()
w
S.display()
w
RESULT:
Thus, the program Display string elements using class has been created
and executed successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
• Modify the table structure by adding one more field namely date of SQL QUERIES AND OUTPUT:
joining. i) Creating Table Employee:
s.
mysql> create table emp(Empno integer(4) primary key, Empname varchar(20),
• Check for Null value in doj of any record.
Desig Varchar(15), Dept varchar(15), Age integer(2), Place varchar(15));
es
• List the employees who joined after 2018/01/01.
ii) Viewing Table Structure:
mysql> desc emp;
pr
+---------------+----------------+------+-------+---------+----------+
| Field | Type | Null | Key | Default | Extra |
ex
+---------------+----------------+------+-------+---------+----------+
| Empno | int(4) | NO | PRI | NULL | |
vi
| Empname | varchar(20) | YES | | NULL | |
| Desig | varchar(15) | YES | | NULL | |
al
| Dept | varchar(15) | YES | | NULL | |
| Age | int(2) | YES | | NULL | |
.k
| Place | varchar(15) | YES | | NULL | |
+--------------+-----------------+------+-------+---------+----------+
w
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
| 102 | Annamalai | Manager | Admin | 32 | Erode |
| 103 | Kumar | Clerk | Accounts | 33 | Ambathur |
s.
| 104 | Madhesh | Manager | Admin | 28 | Anna Nagar |
| 105 | Basha | Officer | Accounts | 31 | Anna Nagar |
es
+---------+-----------------+-------------+--------------+------+-----------------+
pr
v) Adding two more records:
mysql> insert into emp values(106,'Ashok','Manager','Accounts',42,'Erode');
mysql> insert into emp values(107,'Suresh','Officer','Admin',34,'Salem');
ex
mysql> select * from emp;
+-----------+----------------+-------------+-------------+-------+---------------+
vi
| Empno | Empname | Desig | Dept | Age | Place |
+-----------+----------------+-------------+-------------+-------+---------------+
+---------+-----------------+-------------+--------------+------+-----------------+
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
| Empno | int(4) | NO | PRI | NULL | |
| Empname | varchar(20) | YES | | NULL | |
s.
| Desig | varchar(15) | YES | | NULL | |
| Dept | varchar(15) | YES | | NULL | |
| Age | int(2) | YES | | NULL | |
es
| Place | varchar(15) | YES | | NULL | |
| doj | date | YES | | NULL | |
pr
+--------------+-----------------+------+-------+-----------+-----------+
vii) Inserting date of joining to each employee:
mysql> update emp set doj='2015-01-01' where empno=101;
ex
mysql> update emp set doj='2015-06-01' where empno=102;
mysql> update emp set doj='2016-01-01' where empno=103;
vi
mysql> update emp set doj='2016-06-01' where empno=104;
mysql> update emp set doj='2018-01-01' where empno=105;
al
mysql> update emp set doj='2018-06-01' where empno=106;
mysql> update emp set doj='2019-06-01' where empno=107;
.k
mysql> select * from emp;
+-----------+----------------+-------------+-------------+-------+---------------+----------------+
w
| Empno | Empname | Desig | Dept | Age | Place | doj |
+-----------+----------------+-------------+-------------+-------+---------------+----------------+
w
Empty set
in
mysql> select * from emp where doj > '2018-01-01';
s.
+-----------+----------------+-------------+-------------+-------+---------------+----------------+
| Empno | Empname | Desig | Dept | Age | Place | doj |
es
+-----------+----------------+-------------+-------------+-------+---------------+----------------+
| 106 | Ashok | Manager | Accounts | 42 | Erode |2018-06-01 |
| 107 | Suresh | Officer | Admin | 34 | Salem |2019-01-01 |
pr
+---------+-----------------+-------------+--------------+------+-----------------+----------------+
ex
vi
al
.k
w
w
w
RESULT:
Thus, the Queries for Employee Table using MySQL has been created and
executed successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
Sname varchar 15 SQL QUERIES AND OUTPUT:
Age int 2
s.
1) Creating Table – Student:
Dept varchar 10
mysql> create table student(Reg_No char(5), Sname varchar(15), Age integer(2),
Class char 3
es
Dept varchar(10), Class char(3));
Data to be entered
View Table Structure:
Reg_No Sname Age Dept Class mysql> desc student;
pr
M1001 Harish 19 ME ME1 +-----------+-----------------+------+-------+-----------+--------+
M1002 Akash 20 ME ME2 | Field | Type | Null | Key | Default | Extra |
ex
C1001 Sneha 20 CSE CS1 +-----------+-----------------+------+-------+-----------+--------+
C1002 Lithya 19 CSE CS2 | Reg_No | char(5) | YES | | NULL | |
vi
E1001 Ravi 20 ECE EC1 | Sname | varchar(15) | YES | | NULL | |
E1002 Leena 21 EEE EE1 | Age | int(2) | YES | | NULL | |
al
E1003 Rose 20 ECE EC2 | Dept | varchar(10) | YES | | NULL | |
| Class | char(3) | YES | | NULL | |
.k
+-----------+-----------------+------+-------+----------+---------+
Then, Query the followings: 2) Inserting Data into table:
w
i) List the students whose department is “CSE”. mysql> insert into student values('M1001','Harish',19,'ME','ME1');
mysql> insert into student values('M1002','Akash',20,'ME','ME2');
w
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
| M1002 | Akash | 20 | ME | ME2 |
| C1001 | Sneha | 20 | CSE | CS1 |
s.
| C1002 | Lithya | 19 | CSE | CS2 |
| E1001 | Ravi | 20 | ECE | EC1 |
es
| E1002 | Leena | 21 | EEE | EE1 |
| E1003 | Rose | 20 | ECE | EC2 |
pr
+-----------+----------+-------+-------+---------+
3) Other Queries:
ex
i) List the students whose department is “CSE”:
mysql> select * from student where Dept='CSE';
vi
+-----------+-----------+------+--------+-------+
| Reg_No | Sname | Age |Dept | Class|
al +------------+----------+------+--------+-------+
| C1001 | Sneha | 20 | CSE | CS1 |
.k
| C1002 | Lithya | 19 | CSE | CS2 |
+-----------+----------+-------+-------+---------+
w
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
| E1002 | Leena | 21 | EEE | EE1 |
| E1001 | Ravi | 20 | ECE | EC1 |
s.
| C1001 | Sneha | 20 | CSE | CS1 |
+-----------+----------+-------+-------+---------+
es
iv) Modify the class ME2 to ME1:
mysql> update student set class='ME1' where Class='ME2';
pr
mysql> select * from student;
+-----------+-----------+------+--------+-------+
| Reg_No | Sname | Age |Dept | Class|
ex
+------------+----------+------+--------+-------+
| M1001 | Harish | 19 | ME | ME1 |
vi
| M1002 | Akash | 20 | ME | ME1 |
| C1001 | Sneha | 20 | CSE | CS1 |
+-----------+----------+-------+-------+---------+
w
w
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
| M1002 |
| C1001 |
s.
| C1002 |
| E1001 |
es
| E1002 |
| E1003 |
pr
+-----------+
ex
vi
al
.k
w
w
w
RESULT:
Thus, the queries for student table using MySQL has been created and
executed successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
reading the csv file to display the name and the score, If the player name is not
found giving an appropriate message.
s.
CODING:
es
import csv
with open('c:\\pyprg\\player.csv','w') as f:
pr
w = csv.writer(f)
ex
n=1
vi
while(n<=10):
n+=1
w
f.close()
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
Player Name: Sehwag
for row in reader:
Score: 219
s.
Player Name: Rohit lst.append(row)
Score: 264
q=0
es
Player Name: Virat
Score: 183 for row in lst:
Player Name: Ganguly
pr
if searchname in row:
Score: 183
Player Name: Dravid print(row)
ex
Score: 153
Player Name: MS Dhoni q+=1
Score: 224
vi
if(q==0):
Player Name: Karthik
print("String not found")
al
Score: 79
Player Name: Ashwin f.close()
.k
Score: 65
Player File created
w
Enter the name to be searched: Dhoni
['Dhoni', '183']
w
w
RESULT:
Thus, the program Python with CSV has been created and executed
successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
CODING:
s.
import sqlite3
connection =sqlite3.connect("info.db")
es
cursor=connection.cursor()
pr
#cursor.execute(drop table student)
ex
print("Enter 10 students name and their age respectively:")
vi
for i in range(10):
for i in range(n):
w
print("Displaying All the Records From student Table in Descending order of age:")
print(*cursor.fetchall(),sep='\n')
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
SAMPLE OUTPUT:
in
Enter Name: Kumar
Enter Age: 24
s.
Enter Name: Madhesh
Enter Age: 25
es
Enter Name: Guna
Enter Age: 25
pr
Enter Name: Sheik Basha
Enter Age: 26
Enter Name: Ashok
ex
Enter Age: 27
Enter Name: Suresh
vi
Enter Age: 29
Enter Name: Babu
al
Enter Age: 30
Enter Name: Pradish
.k
Enter Age: 26
Displaying All the Records From student Table in Descending order of age:
w
('Babu', 30)
('Suresh', 29)
w
('Annamalai', 27)
('Ashok', 27)
w
RESULT:
('Sheik Basha', 26)
('Pradish', 26) Thus, the program Python with MySQL has been created and executed
('Aalayam', 25) successfully.
('Madhesh', 25)
('Guna', 25)
('Kumar', 24)
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
in
CODING:
import matplotlib.pyplot as plt
s.
marks=[]
es
i=0
pr
subjects=["Tamil","English","Maths","Physics","Computer"]
ex
while i<5:
vi
i+=1
al for j in range(len(marks)):
.k
print("{}.{} Mark ={}".format(j+1,subjects[j],marks[j]))
w
plt.pie(marks,labels=subjects,autopct="%.2f")
w
plt.axes().set_aspect("equal")
w
plt.show()
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in
www.kalviexpress.in www.kalviexpress.in
SAMPLE OUTPUT:
Enter Mark = 70
Enter Mark = 80
Enter Mark = 90
Enter Mark = 95
in
Enter Mark = 100
1.Tamil Mark =70
s.
2.English Mark =80
3.Maths Mark =90
es
4.Physics Mark =95
5.Computer Mark =100
pr
ex
vi
al
.k
w
w
w
RESULT:
Thus, the program Python Graphics with Pip has been created and
executed successfully.
Prepared by Parkunan T, PG Asst. in Computer Science, MHSS, Chengam, Tiruvannamalai Cell: 9655 966 906 Mail: [email protected]
www.kalviexpress.in www.kalviexpress.in