[go: up one dir, main page]

0% found this document useful (0 votes)
33 views36 pages

Practical File (CS) (2024-25) 2

The document is a practical file for a Computer Science course, submitted by Tarun Singh for the academic year 2024-2025. It includes various Python programs demonstrating arithmetic operations, file handling, and database integration with MySQL. Each program is accompanied by its output and serves as a record of the student's practical work in the subject.

Uploaded by

gaje4643
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views36 pages

Practical File (CS) (2024-25) 2

The document is a practical file for a Computer Science course, submitted by Tarun Singh for the academic year 2024-2025. It includes various Python programs demonstrating arithmetic operations, file handling, and database integration with MySQL. Each program is accompanied by its output and serves as a record of the student's practical work in the subject.

Uploaded by

gaje4643
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Computer Science Practical File

Submitted By:- Tarun Singh SubmittedTo:Geetanjali.


Roll No. :- 31
Board Roll no. :-17617488

PRACTICAL FILE – XII (COMPUTER SCIENCE) Page 1 / 36


CERTIFICATE

CLASS: XII-B YEAR: 2024-2025

This is to certify that Investigatory Project is successfully completed by


Tarun Singh of Class: XII, Division: B
Roll no.: 31 for the academic year 2024-2025 in the School
Computer lab.

Head Teacher External Internal Examiner


Signature: Examiner (Subject Teacher)

Date: / / 25 Department of: COMPUTER SCI.

Principal
PROGRAM 1
CREATING A MENU DRIVEN PROGRAM TO PERFORM ARITHMETIC OPERATIONS

OUTPUT
PROGRAM 2
CREATING A PYTHON PROGRAM TO DISPLAY FIBONACCI SERIES

OUTPUT
PROGRAM3
CREATING A MENU DRIVEN PROGRAM TO FIND FACTORIAL AND SUM OF LIST OF NUMBERS USING
FUNCTION.
OUTPUT
PROGRAM 4
CREATING A PYTHON PROGRAM TO IMPLEMENT RETURNING VALUE(S) FROM FUNCTION

OUTPUT
PROGRAM 5
CREATING A PYTHON PROGRAM TO IMPLEMENT MATHEMATICAL FUNCTIONS

OUTPUT
PROGRAM 6
CREATING A PYTHON PROGRAM TO GENERATE RANDOM NUMBER BETWEEN 1 TO 6

OUTPUT
PROGRAM 7
CREATING A PYTHON PROGRAM TO READ A TEXTFILE LINE BY LINE AND DISPLAY EACH WORD
SEPARATED BY '#'

OUTPUT
Story.txt:
PROGRAM 8
CREATING A PYTHON PROGRAM TO READ A TEXT FILE AND DISPLAY THENUMBEROF
VOWELS/CONSONANTS/LOWERCASE/UPPER CASECHARACTERS.

OUTPUT
Story.txt:
PROGRAM 9
CREATING PYTHON PROGRAM TO DISPLAY SHORT WORDS FROM A TEXTFILE

OUTPUT
Poem.txt:

PythonExecutedProgramOutput:
PROGRAM 10
CREATING A PYTHON PROGRAM TO COPY PARTICULAR LINES OF A TEXTFILE INTO
AN ANOTHER TEXT FILE

OUTPUT
Sample.txt:

PythonExecutedProgramOutput:

New.txt:
PROGRAM 11
CREATING A PYTHON PROGRAM TO CREATE AND SEARCH RECORDS IN BINARY FILE
OUTPUT
PROGRAM 12
CREATING A PYTHON PROGRAM TO CREATE AND UPDATE/MODIFY RECORDS IN
BINARY FILE
OUTPUT
PROGRAM 13
CREATING A PYTHON PROGRAM TO CREATE AND SEARCH EMPLOYEE’S RECORD IN CSV FILE.
OUTPUT
PROGRAM 14
CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(LIST)
OUTPUT
PROGRAM 15
CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(Dictionary)
OUTPUT
PROGRAM 16
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON

(CREATING DATABASE AND TABLE)


OUTPUT
PROGRAM 17
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON

(INSERTING RECORDS AND DISPLAYING RECORDS)


OUTPUT
PROGRAM 18
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (SEARCHING AND

DISPLAYING RECORDS)

OUTPUT

PROGRAM 19
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (UPDATING

RECORDS)
OUTPUT

PROGRAM 20
Perform all the operations with reference to table ‘Employee’ through
MySQL-Python connectivity.

Solution:
import MySQLdb

# Using connect method to connect database

db1 = MySQLdb.connect("localhost","root","","TESTDB" )#

using cursor() method for preparing cursor

cursor = db1.cursor()

# Preparing SQL statement to create EMP table

sql = "CREATE TABLE EMP(empno integer primary key,ename varchar(25) not null,salary
float);"

cursor.execute(sql)

# disconnect from serverdb1.close()


Inserting a record in ‘emp’

import MySQLdb

db1 = MySQLdb.connect("localhost","root","","TESTDB"

)cursor = db1.cursor()

# Prepareing SQL statement to insert one record with the given

valuessql = "INSERT INTO EMP VALUES (1,'ANIL

KUMAR',86000);"

try:

cursor.execute(sql)

db1.commit()
except:

db1.rollback()

db1.close()

Fetching all the records from EMP table having salary more than 70000.

import MySQLdb

db1 = MySQLdb.connect("localhost","root","","TESTDB"

)cursor = db1.cursor()

sql = "SELECT * FROM EMP WHERE SALARY > 70000;"

try:

cursor.execute(sql)

#using fetchall() function to fetch all records from the table EMP and store in
resultset

resultset =

cursor.fetchall()for row in

resultset:

print

(row)except:

print ("Error: unable to fetch data")

db1.close()
Updating record(s) of the table using UPDATE

import MySQLdb

db1 = MySQLdb.connect("localhost","root","","TESTDB"

)cursor = db1.cursor()

#Preparing SQL statement to increase salary of all employees whose salary is less
than 80000

sql = "UPDATE EMP SET salary = salary +1000 WHERE

salary<80000;"try:

cursor.execute(sql)

db1.commit()

except:

db1.rollback()

db1.close()
Deleting record(s) from table using DELETE

import MySQLdb

db1 = MySQLdb.connect("localhost","root","","TESTDB" )cursor

= db1.cursor()

sal=int(input("Enter salary whose record to be deleted : ")) #Preparing

SQL statement to delete records as per given conditionsql = "DELETE

FROM EMP WHERE salary =sal”

try:

cursor.execute(sql)

print(cursor.rowcount, end=" record(s) deleted ")

db1.commit()

except:

db1.rollback()

db1.close()

Output

>>> Enter salary whose record to be deleted: 800001

record(s) deleted

>>>

You might also like