12 CS EM Kalviexpress Practical Hand Book

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

www.kalviexpress.in www.kalviexpress.

in

+2 COMPUTER SCIENCE PRACTICAL HAND BOOK


INDEX
Instructions:
Question
1. Eight exercises from Python and Two from MySQL are practiced in the Sl. No. Program Name
Number
practical classes

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

10 PY10 PYTHON GRAPHICS WITH PIP


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

QUESTION: 1 a) CALCULATE FACTORIAL


Write a program to calculate the factorial of the given number using for
loop. AIM:

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

QUESTION: 1 b) SUM OF SERIES


2 3 n
Write a program to sum the series:1/1 + 2 /2 + 3 /3 + … + n /n.

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

QUESTION: 2 a) ODD OR EVEN


Write a program to using functions to check whether a number is odd or AIM:
even. To write a program using functions for checking whether a number is odd
or even.

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):

al print("The given number is Odd")


.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 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

QUESTION: 2 b) REVERSE THE STRING

Write a program to create a mirror of given string. For example, AIM:


“wel” = “lew“. To write a program for creating a mirror of given string.

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:

Enter a String: Computer

The mirror image of the given string is: retupmoC

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:

Numbers from 1 to 10...


[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
The values after removed odd numbers...
[2, 4, 6, 8, 10]

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

QUESTION: 4. GENERATE PRIME NUMBERS AND SET OPERATIONS


Write a Program that generates a set of prime numbers and another AIM:
set of odd numbers. Display the result of union, intersection, difference and To write a program for generating a set of prime numbers and another set
symmetric difference operations. of odd numbers and displaying the result of set operations.

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

print("Symmetric Difference: ",odd.symmetric_difference(primes))

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

QUESTION: 5. DISPLAY STRING ELEMENTS – USING CLASS


Write a program to accept a string and print the number of
uppercase, lowercase, vowels, consonants and spaces in the given string AIM:
using Class. To write a program for accepting a string and printing the number of
uppercase, lowercase, vowels, consonants and spaces in the given string

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

SAMPLE OUTPUT: def count_consonents(self):


Enter a String: Computer Science for ch in self.string:
The given String contains... if(ch not in ('A','a','e','E','I','i','O','o','u','U'," ")):
2 Uppercase self.consonents+=1
13 Lowercase def count_spaces(self):
6 vowels for ch in self.string:

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

QUESTION: 6. MYSQL – EMPLOYEE TABLE


Create an Employee Table with the fields Empno, Empname, Desig, AIM:
Dept, Age and Place. Enter five records into the table To create SQL queries for creating a table and perform adding records,
• Add two more records to the table. modifying table structure, checking null values and selecting records using where
clause.

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

iii) Inserting Data into Table:


w

mysql> insert into emp values(101,'Aalayam','Officer','Accounts',45,'Salem');


mysql> insert into emp values(102,'Annamalai','Manager','Admin',32,'Erode');
w

mysql> insert into emp values(103,'Kumar','Clerk','Accounts',33,'Ambathur');


mysql> insert into emp values(104,'Madhesh','Manager','Admin',28,'Anna Nagar');
mysql> insert into emp values(105,'Basha','Officer','Accounts',31,'Anna Nagar');

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

iv) Select all the records:


mysql> select * from emp;
+-----------+----------------+-------------+-------------+-------+---------------+
| Empno | Empname | Desig | Dept | Age | Place |
+-----------+----------------+-------------+-------------+-------+---------------+
| 101 | Aalayam | Officer | Accounts | 45 | Salem |

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 |
+-----------+----------------+-------------+-------------+-------+---------------+

al | 101 | Aalayam | Officer | Accounts | 45 | Salem


| 102 | Annamalai | Manager | Admin | 32 | Erode
|
|
.k
| 103 | Kumar | Clerk | Accounts | 33 | Ambathur |
| 104 | Madhesh | Manager | Admin | 28 | Anna Nagar |
w

| 105 | Basha | Officer | Accounts | 31 | Anna Nagar |


w

| 106 | Ashok | Manager | Accounts | 42 | Erode |


| 107 | Suresh | Officer | Admin | 34 | Salem |
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

vi) Adding one more field in Table:


mysql> Alter table emp add (doj date);
mysql> desc emp;
+---------------+----------------+------+-------+-----------+----------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------+------+-------+-----------+----------+

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

| 101 | Aalayam | Officer | Accounts | 45 | Salem |2015-01-01 |


| 102 | Annamalai | Manager | Admin | 32 | Erode |2015-06-01 |
w

| 103 | Kumar | Clerk | Accounts | 33 | Ambathur |2016-01-01 |


| 104 | Madhesh | Manager | Admin | 28 | Anna Nagar |2016-06-01 |
| 105 | Basha | Officer | Accounts | 31 | Anna Nagar |2018-01-01 |
| 106 | Ashok | Manager | Accounts | 42 | Erode |2018-06-01 |
| 107 | Suresh | Officer | Admin | 34 | Salem |2019-01-01 |
+---------+-----------------+-------------+--------------+------+-----------------+---------------+
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

viii) Checking null value in doj:

mysql> select * from emp where doj is null;

Empty set

ix) List the employee who joined after 2018-01-01:

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

QUESTION: 7. MYSQL - STUDENT TABLE


Create Student table with following fields and enter data as given in
the table below AIM:
Field Type Size To create SQL queries for given student table and perform some queries.
Reg_No char 5

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

ii) List all the students of age 20 and more in ME department.


iii) List the students department wise. mysql> insert into student values('C1001','Sneha',20,'CSE','CS1');
mysql> insert into student values('C1002','Lithya',19,'CSE','CS2');
w

iv) Modify the class ME2 to ME1.


v) Check for the uniqueness of Register no. mysql> insert into student values('E1001','Ravi',20,'ECE','EC1');
mysql> insert into student values('E1002','Leena',21,'EEE','EE1');
mysql> insert into student values('E1003','Rose',20,'ECE','EC2');

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

View all records:


mysql> select * from student;
+-----------+-----------+------+--------+-------+
| Reg_No | Sname | Age |Dept | Class|
+------------+----------+------+--------+-------+
| M1001 | Harish | 19 | ME | ME1 |

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

ii) List all the students of age 20 and more in ME department:


w

mysql> select * from student where Age>=20 and Dept='ME';


+-----------+-----------+------+--------+-------+
w

| Reg_No | Sname | Age |Dept | Class|


+------------+----------+------+--------+-------+
| M1002 | Akash | 20 | ME | ME2 |
+-----------+----------+-------+-------+---------+

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

iii) List the students department wise:


mysql> select * from student group by Dept order by Sname;
+-----------+-----------+------+--------+-------+
| Reg_No | Sname | Age |Dept | Class|
+------------+----------+------+--------+-------+
| M1001 | Harish | 19 | ME | ME1 |

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 |

al | C1002 | Lithya | 19 | CSE | CS2 |


| E1001 | Ravi | 20 | ECE | EC1 |
.k
| E1002 | Leena | 21 | EEE | EE1 |
| E1003 | Rose | 20 | ECE | EC2 |
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

v) Check for the uniqueness of Register no.:


mysql> select distinct Reg_No from student;
+------------+
| Reg_No |
+------------+
| M1001 |

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

QUESTION: 8. PYTHON WITH CSV


Write a program using python to get 10 players name and their score.
Write the input in a csv file. Accept a player name using python. Read the csv file AIM:
to display the name and the score. If the player name is not found give an To write a program using python for getting 10 players name and their
appropriate message. score, writing the input in a csv file, accepting a player name using python,

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):

al name=input("Player Name: ")


.k
score=int(input("Score: "))
w
w.writerow([name,score])
w

n+=1
w

print("Player File created")

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

SAMPLE OUTPUT: searchname=input("Enter the name to be searched: ")

Player Name: Dhoni f=open('c:\\pyprg\\player.csv','r')


Score: 183
reader=csv.reader(f)
Player Name: Sachin
Score: 200 lst=[]

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

QUESTION: 9. PYTHON WITH SQL


Create a SQL table using python and accept 10 names and age. sort in
descending order of age and display. AIM:
To create a SQL table using python and accepting 10 names, age and
sorting in descending order of age and displaying the result.

in
CODING:

s.
import sqlite3

connection =sqlite3.connect("info.db")

es
cursor=connection.cursor()

pr
#cursor.execute(drop table student)

cursor.execute("create table student(name,age)")

ex
print("Enter 10 students name and their age respectively:")

vi
for i in range(10):

who=[input("Enter Name: ")]

al age=[int(input("Enter Age: "))]


.k
n=len(who)
w

for i in range(n):
w

cursor.execute("insert into student values(?,?)",(who[i],age[i]))


w

cursor.execute("select * from student order by age desc")

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:

Enter 10 students name and their age respectively:


Enter Name: Aalayam
Enter Age: 25
Enter Name: Annamalai
Enter Age: 27

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

QUESTION: 10. PYTHON GRAPHICS WITH PIP


Write a program to get five marks using list and display the marks in pie
chart. AIM:
To write a program for getting five marks using list and displaying the
marks in pie chart.

in
CODING:
import matplotlib.pyplot as plt

s.
marks=[]

es
i=0

pr
subjects=["Tamil","English","Maths","Physics","Computer"]

ex
while i<5:

marks.append(int(input("Enter Mark = ")))

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

You might also like