Document (1)
Document (1)
SCHOOL
Computer Science Practical File
2024-2025
Submitted by:
Name – Khushi Nagar
Class – XII-A
CBSE Roll Number –
Principal
ACKNOWLEDGMENTS
It is with pleasure that I acknowledge my
sincere gratitude to our teacher ,Mr PRAMOD
SHARMA,PGT (CS) who taught and undertook
the responsibility of teaching the subject
computer science . I have been greatly
benefited from his classes.
I am especially indebted to our principal MRS
GARGI GHOSH KANSABANIK who has always
been a source of encouragement and support
and without whose inspiration this project
would not have been a successful l would like
to place on record heartfelt thanks to her.
Finally , I would like to express my sincere
appreciation for all the other students for my
batch their friendship and the fine time that
we all shared together.
INDEX
Python programs
1. Creating a python program display fibonacci series ?
2. Creating a menu drive and program to find factorial and sum list of
numbers using function?
4. Creating a python program to read a text file line by line and display
each word separated by ‘#’?
SQL QUERIES
12. SQL COMMANDS EXERCISE – 1
Exp-1
Aim:
Source code:
Def fibonacci(n):
Fib_series = [0, 1]
Fib_series.append(fib_series[-1] + fib_series[-2])
Return fib_series
Print(fibonacci(n))
Result:
Thus, the above Python Program has been executed and the output is
verified successfully.
Sample output:
Exp-2:
Creating a menu drive and program to find factorial and sum list of
numbers using function?
Aim:
To write Python program to define the function check (no1,no2) that take two
numbers and returns the number that has minimum ones digit.
Source code:
If __name__ == “__main__”:
Main()
Result:
Thus, the above Python program has been executed and the output is
verified successfully.
Sample output:
Exp–3
Aim:
Source code:
Result:
Thus, the above Python program has been executed and the output is
verified successfully.
Sample output:
Exp-4:
Creating a python program to read a text file line by line and display
each word separated by ‘#’?
Aim:
To write a python program to read text file “Story.tx.t” line by line and display
each word separated by ‘#’.
Source code:
Def read_file(filename):
“””Read a text file line by line and display each word separated by ‘#’”””
Try:
Words = line.split()
Print(‘#’.join(words))
Except FileNotFoundError:
Def main():
Filename = “Story.txt”
Read_file(filename)
If __name__ == “__main__”:
Main()
Result:
Thus the above Python program has been executed and the output is verified
successfully.
Sample Output:
Aim:
To write a method to display in python, to read the lines from poem.txt and
display those words which are less than 5 characters.
Source code:
Def read_short_words(filename):
“””Read a text file and display words with less than 5 characters”””
Try:
Words = line.split()
If len(word) < 5:
Print(word)
Def main():
Filename = “poem.txt”
Read_short_words(filename)
If __name__ == “__main__”:
Main()
Result:
Thus , the above Python program has been executed and the output is
verified successfully.
Sample output:
Poem.txt:
The following words are lesser than 5 character rays of on the sky.
Exp-6:
Aim:
To write a python program to read line from text file ‘Sample.txt’ and copy
those lines into another file which are starting with alphabets ‘a’ and ‘A’.
Source code:
Def copy_lines(filename):
“””Read a text file and copy lines starting with ‘a’ or ‘A’ to another file”””
Try:
Lines = file.readlines()
If line.strip().lower().startswith(‘a’):
Output_file.write(line)
Except FileNotFoundError:
Def main():
Filename = “Sample.txt”
Copy_lines(filename)
If __name__ == “__main__”:
Main()
Result:
This , the above python program has been executed and the output is
verified successfully.
Sample output:
Sample.txt
Exp-7:
Aim:
(iii) To display the elements of the stack (after performing PUSH or POP).
Source code:
Result:
Thus , the above Python program has been executed and the output is
verified successfully.
Sample output:
Aim:
Result:
Thus , the above Python program has been executed and the output is
verified successfully.
Sample output:
Aim:
Source code:
Import mysql.connector
Username = ‘your_username’
Password = ‘your_password’
Host = ‘localhost’
Database = ‘your_database’
Def create_connection():
Try:
Connection = mysql.connector.connect(
Host=host,
User=username,
Password=password,
Database=database
Return connection
Except Error as e:
Return None
Def insert_records(connection):
Try:
Cursor = connection.cursor()
Query = “””
“””
Records = [
Cursor.executemany(query, records)
Connection.commit()
Except Error as e:
Def retrieve_records(connection):
Try:
Cursor = connection.cursor()
Cursor.execute(query)
Rows = cursor.fetchall()
Print(row)
Except Error as e:
Connection = create_connection()
If connection:
Insert_records(connection)
Retrieve_records(connection)
Connection.close()
Result:
Thus , the above Python program has been executed and output is verified
successfully.
Sample output:
Aim:
Source code:
Import mysql.connector
Username = ‘your_username’
Password = ‘your_password’
Host = ‘localhost’
Database = ‘your_database’
Def create_connection():
Try:
Connection = mysql.connector.connect(
Host=host,
User=username,
Password=password,
Database=database
Return connection
Except Error as e:
Return None
Try:
Cursor = connection.cursor()
Cursor.execute(query, (emp_id,))
Row = cursor.fetchone()
If row:
Print(“Employee found:”)
Print(row)
Else:
Except Error as e:
Connection = create_connection()
If connection:
Search_employee(connection, emp_id)
Connection.close()
Result:
Thus , the above Python program has been executed and the output is
verified successfully.
Sample output:
Aim:
Source code:
Import mysql.connector
Username = ‘your_username’
Password = ‘your_password’
Host = ‘localhost’
Database = ‘your_database’
Def create_connection():
Try:
Connection = mysql.connector.connect(
Host=host,
User=username,
Password=password,
Database=database
Return connection
Except Error as e:
Print(f”Error connecting to database: {e}”)
Return None
Try:
Cursor = connection.cursor()
Cursor.execute(query, (emp_id,))
Row = cursor.fetchone()
If row:
Connection.commit()
Else:
Except Error as e:
# Main program
Connection = create_connection()
If connection:
Connection.close()
Result:
Thus , the above Python program has been executed and the output is
verified successfully.
Sample output:
Aim:
To write queries for the following questions based on the given table:
SHOW DATABASES;
(e) Write a query to list all the tables that exist in the current database.
SHOW TABLES;
OUTPUT:
Exp-13:
Aim:
To write queries for the following questions based on the given table:
(a) Create a query to insert all the rows of above table into Infotable.
INSERTINTOSTUVALUES(l,’Arun’,’M’,24,’COMPUTER’,’l997-Ol-10’,120);
INSERTINTOSTUVALUES(2,’Ankit’,’M’,2l,’HISTORY’,’l998-O3-24’,2OO);
INSERTINTOSTUVALUES(3,’Anu’,’F’,2O,’HINDI’,’l996-l2-l2’,3OO);
INSERTINTOSTUVALUES(4,’Bala’,’M’,l9,NULL,’l999-O7-Ol’,4OO);
INSERTINTOSTUVALUES(5,’Charan’,’M’,l8,’HINDI’,’l997-O6-27’,25O);
INSERTINTOSTUVALUES(6,’Deepa’,’F’,l9,’HISTORY’,’l997-O6-27’,3OO);
INSERTINTOSTUVALUES(7,’Dinesh’,’M’,22,’COMPUTER’,’l997-O2-25’,2lO);
INSERTINTOSTUVALUES(8,’Usha’,’F’,23,NULL,’l997-O7-3l’,2OO);
(b) Write a query to display all the details of employee from the above
table STUDENTS.
SELECT*FROM STUDENTS;
OUTPUT:
(c) Write a query to display Rollno, Name and Department of the
student from STUDENTS Table.
SELECT ROLLNO,NAME,DEPT FROM STUDENTS;
(d) Write a query to select distinct department from STUDENTS table.
SELECT DISTINCT (DEPT) FROM STUDENTS;
OUTPUT:
Exp-14:
Aim:
To write queries for the following question based on the given table:
OUTPUT:
(b) Write a query to list name of the students whose ages are between
18 to 20.
SELECT NAMES FROM STUDENT WHERE AGE BETWEEN 18 AND 20;
OUTPUT:
(c) Write a query to display the name of the student whose name is
Exp-15:
Aim:
To write queries for the following question based on the given table:
(b) Write a query to change the fees of student to 170 whose roll
number is 1 , if the existing fees is less than 130.
UPDATE STUDENT SET FEES=170 WHERE ROLL NO=1 AND
FEES<130;
(c) Write a query to add a new column Area of type varchar in table
STUDENTS.
ALTER TABLE STUDENT ADD AREA VARCHAR (20);
OUTPUT:
(d) Write a query to display name of all student whose area contains
null.
OUTPUT:
(e) Write a query to delete Area column from the table STUDENTS.
ALTER TABLE STUDENTS DROP AREA;
OUTPUT:
Exp-16:
Aim:
To write queries for the following question based on the given table:
(a) To display the average price of all the uniform of Raymond company
from table cost.
OUTPUT:
(d) To display the company where the number of uniform sizes more
than 2.
SELECT COMPANY,COUNT(*) FROM COST GROUP BY COMPANY
HAVING COUNT(*)>2;
OUTPUT: