0% found this document useful (0 votes)
8 views12 pages

Raghavcspractical

Uploaded by

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

Raghavcspractical

Uploaded by

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

CERTIFICATE

This is to certify that Raghav Singh,


student of class 12th has successfully
completed the research on the project,
School Management Systems under the
guidance of Mrs. Amoli Chakraborty during
the year of 2024-2025 in partial
fulfillment of computer science practical
examination conducted by Bedi
International School, Bareilly.

Examiner Signature Principal Signature


__________________ ___________________
ACKNOWLEDGEMENT

We owe our heartfelt gratitude to everyone


who supported us in successfully completing
this project.
First and foremost, we thank God for giving
us the strength, wisdom, and determination
to accomplish this task. We are deeply
grateful to our principal, Mrs._JK Sawhney,
and our Computer Science teacher,
Mrs.Amoli Chakraborty, for their
invaluable guidance and encouragement,
which shaped this project and ensured its
success.
We also extend our thanks to our parents,
whose constant support and advice guided
us through every challenge we faced during
this journey.
Lastly, we sincerely thank all those who
contributed, directly or indirectly, to
making this project a reality. Your support
means the world to us.
PROGRAMS

text files programs:

Q1 Count words in a text file.


file = open("project.txt", 'r')
text = file.read()
words = text.split()
print("Number of words:", len(words))
file.close()

output:
Number of words: 1

Q2 Write user input to a text file.


data = input("Enter text to write to file: ")
file = open("project.txt", 'w')
file.write(data)
file.close()

output:
Enter text to write to file: abcdefg

Q3 Find the longest line in a text file.


file = open("project.txt", 'r')
lines = file.readlines()
longest_line = max(lines, key=len)
print("Longest line:", longest_line)
file.close()

output:
Longest line: abcdedg
binary files programs:

Q1 Write a list of numbers to a binary file.


import pickle

filename = "project.dat"
numbers = [1, 2, 3, 4, 5]
file = open(filename, 'wb')
pickle.dump(numbers, file)
print("successfully added data.")
file.close()

output:
successfully added data.

Q2 Read integers from a binary file and display their sum.


import pickle

filename = "project.dat"
file = open(filename, 'rb')
numbers = pickle.load(file)
print("Sum of numbers:", sum(numbers))
file.close()

output:
Sum of numbers: 15

Q3 Append data to an existing binary file.

import pickle

filename = "project.dat"
file = open(filename, 'rb')
numbers = pickle.load(file)
file.close()

new_numbers = [6, 7, 8]
numbers.extend(new_numbers)
file = open(filename, 'wb')
pickle.dump(numbers, file)
print("successfully appended data.")
file.close()

output:
successfully appended data.
CSV files programs:

Q1 Read a CSV file and display its contents.


import csv

filename = "project.csv"
file = open(filename, 'r')
reader = csv.reader(file)
for row in reader:
print(row)
file.close()

output:
['Name\tClass']
['Raghav\tXII-A']
['Shikhar\tXII-A']
['Aarab\tXII-A']

Q2 Write a dictionary into a CSV file.

import csv

filename = "project.csv"
data = [{"Name": "Raghav", "Age": 16}, {"Name": "Vinay", "Age": 15}]
file = open(filename, 'w', newline='')
writer = csv.DictWriter(file, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)
print("successfully added data.")
file.close()

output:
Sum of numbers: 15

Q3 Update a specific row in a CSV file.

import csv

file = open("project.csv", 'r')


rows = list(csv.reader(file))
file.close()
new_row = ["Yash", 17]
rows[1] = new_row
file = open("project.csv", 'w', newline='')
writer = csv.writer(file)
writer.writerows(rows)
print("successfully updated.")
file.close()

output:
successfully updated.
stack programs:
Q1 Stack implementation using a list.

stack = []
stack.append(1)
stack.append(2)
stack.append(3)
print("Popped item:", stack.pop())

output:
Popped item: 3

Q2 Reverse a string using a stack.

string = "hello"
stack = []
for char in string:
stack.append(char)
reversed_string = ""
while stack:
reversed_string += stack.pop()
print("Reversed string:", reversed_string)

output:
Reversed string: olleh

Q3 write push function for stack.

stack = []
def push(item):
stack.append(item)
print(f"Pushed {item} onto the stack.")
push(10)
push(20)
push(30)
print("Stack:", stack)

output:
Pushed 10 onto the stack.
Pushed 20 onto the stack.
Pushed 30 onto the stack.
Stack: [10, 20, 30]
list programs:
Q1 find largest number in list.

numbers = [3, 1, 7, 5, 9, 2]
largest = numbers[0]
for num in numbers:
if num > largest:
largest = num
print("The largest number is:", largest)

output:
The largest number is: 9

Q2 find smallest number in list.

numbers = [5, 8, 2, 9, 1, 6]
smallest = numbers[0]
for num in numbers:
if num < smallest:
smallest = num
print("The smallest number is:", smallest)

output:
The smallest number is: 1

Q3 remove duplicate elements from a list.

numbers = [1, 2, 3, 2, 4, 1, 5]
unique_numbers = []
for num in numbers:
if num not in unique_numbers:
unique_numbers.append(num)
print("List without duplicates:", unique_numbers)

output:
List without duplicates: [1, 2, 3, 4, 5]
tuple programs:

Q1 find the index of a element in a tuple.

my_tuple = (10, 20, 30, 40, 50)


element = 30
index = my_tuple.index(element)
print("Index of", element, "is:", index)

output:
Index of 30 is: 2

Q2 count occurrence of an element in a tuple.

my_tuple = (1, 2, 3, 1, 4, 2, 5)
count_dict = {}
for item in my_tuple:
if item in count_dict:
count_dict[item] += 1
else:
count_dict[item] = 1
print("Element counts:", count_dict)

output:
Element counts: {1: 2, 2: 2, 3: 1, 4: 1, 5: 1}

Q3 check if some element exists in a tuple.

my_tuple = (10, 20, 30, 40)


element = 30
if element in my_tuple:
print(element, "is in the tuple.")
else:
print(element, "is not in the tuple.")

output:
30 is in the tuple.
dictionary programs:

Q1 Write a function addDict(dict1, dict2) that returns a new


dictionary with the union of two dictionaries. If a key
appears in both, use the value from either dictionary.

def addDict(dict1, dict2):


union_dict = {}
for key, value in dict1.items():
union_dict[key] = value
for key, value in dict2.items():
union_dict[key] = value
return union_dict

dict1 = {'a': 1, 'b': 2}


dict2 = {'b': 3, 'c': 4}
result = addDict(dict1, dict2)
print("Union of dict1 and dict2:", result)

output:
Union of dict1 and dict2: {'a': 1, 'b': 3, 'c': 4}

Q2 Write a program to sort a dictionary's keys using Bubble


sort and produce the sorted keys as a list.

my_dict = eval(input("Enter the dictionary: "))


keys = list(my_dict.keys())
l = len(keys)
for i in range(l):
for j in range(0, l - i - 1):
if keys[j] > keys[j + 1]:
keys[j], keys[j + 1] = keys[j + 1], keys[j]
print("Sorted keys:",keys)

output:
Enter the dictionary: {'c':10, 'f':87, 'r':23, 'a':5}
Sorted keys: ['a', 'c', 'f', 'r']

Q3 words occurrence in a string.

string = "hello world hello"


words = string.split()
freq = {}
for word in words:
freq[word] = freq.get(word, 0) + 1
print("Word frequency:", freq)

output:
Word frequency: {'hello': 2, 'world': 1}
python-SQL connectivity programs.

Q1 Connect to a database and create a table.

import mysql.connector

connection = mysql.connector.connect(host='localhost', user='root',


password='12345', database='practicaldb')
cursor = connection.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS students (id INT, name
VARCHAR(255))")
print("table successfully created.")
connection.close()

output:
table successfully created.

Q2 inserting multiple records to a table.

import mysql.connector

connection = mysql.connector.connect(host='localhost', user='root',


password='12345', database='practicaldb')
cursor = connection.cursor()
records = [(1, 'Alice'), (2, 'Bob')]
cursor.executemany("INSERT INTO students (id, name) VALUES (%s, %s)",
records)
print("records successfully added.")
connection.commit()
connection.close()

output:
records successfully added.

Q3 fetch and display records.

import mysql.connector

connection = mysql.connector.connect(host='localhost', user='root',


password='12345', database='practicaldb')
cursor = connection.cursor()
cursor.execute("SELECT * FROM students")
for record in cursor.fetchall():
print(record)
connection.close()

output:
(1, 'Alice')
(2, 'Bob')
SQL queries:

single table:

STUDENT TABLE
+--------+--------------+----------------+------------------+----------------+-----------+
| rollno | stname | clas | section | sub1 | sub2 | sub3 |
+--------+--------------+----------------+------------------+----------------+-----------+
| 104 | Aarav Sharma | 12 | A | Maths | Physics | Chemistry |
| 105 | Isha Kapoor | 11 | B | English | Biology | History |
| 106 | Vihaan Gupta | 10 | A | Computer Science | Maths | English |
| 107 | Ananya Reddy | 9 | C | Hindi | Geography | Maths |
| 108 | Madhav Joshi | 8 | D | Science | Social Studies | Maths |
+--------+--------------+------+---------+-----------------------------------+-----------+

SELECT * FROM STUDENT


WHERE stname LIKE 'A%';

output:
+--------+--------------+------+---------+-------+-----------+-----------+
| rollno | stname | clas | section | sub1 | sub2 | sub3 |
+--------+--------------+------+---------+-------+-----------+-----------+
| 104 | Aarav Sharma | 12 | A | Maths | Physics | Chemistry |
| 107 | Ananya Reddy | 9 | C | Hindi | Geography | Maths |
+--------+--------------+------+---------+-------+-----------+-----------+

INSERT INTO student


VALUES(109, 'Raghav Singh', 12, 'A', 'Maths', 'Physics', 'Python');

output:
+--------+--------------+------+---------+------------------+----------------+-----------+
| rollno | stname | clas | section | sub1 | sub2 | sub3 |
+--------+--------------+------+---------+------------------+----------------+-----------+
| 104 | Aarav Sharma | 12 | A | Maths | Physics | Chemistry |
| 105 | Isha Kapoor | 11 | B | English | Biology | History |
| 106 | Vihaan Gupta | 10 | A | Computer Science | Maths | English |
| 107 | Ananya Reddy | 9 | C | Hindi | Geography | Maths |
| 108 | Madhav Joshi | 8 | D | Science | Social Studies | Maths |
| 109 | Raghav Singh | 12 | A | Maths | Physics | Python |
+--------+--------------+------+---------+------------------+----------------+-----------+
two tables:

academic_info table:
+------------+-------+---------+------------+----------+------------------+
| student_id | class | section | subject1 | subject2 | subject3 |
+------------+-------+---------+------------+----------+------------------+
| 1 | 10 | A | Math | Science | History |
| 2 | 12 | B | English | Physics | Chemistry |
| 3 | 11 | C | Biology | Math | Geography |
| 4 | 9 | A | History | Math | Computer Science |
| 5 | 10 | B | Literature | Biology | Math |
+------------+-------+---------+------------+----------+------------------+

student_details table
+------------+---------------+--------------------------+----------------+
| student_id | name | address | contact_number |
+------------+---------------+--------------------------+----------------+
| 1 | John Doe | 123 Main St, New York | 555-1234 |
| 2 | Jane Smith | 456 Oak Ave, Los Angeles | 555-5678 |
| 3 | Alice Brown | 789 Pine Rd, Chicago | 555-8765 |
| 4 | Bob Johnson | 321 Elm St, Miami | 555-4321 |
| 5 | Charlie Davis | 654 Cedar Blvd, Houston | 555-1111 |
+------------+---------------+--------------------------+----------------+

SELECT name, class, section, contact_number


FROM academic_info, student_details
WHERE academic_indo.student_id = student_details.student_id;

output:
+------------+----------+---------+------------+------------+-----------+----------+
| booking_id | guest_id | room_id | status | first_name | last_name | phone |
+------------+----------+---------+------------+------------+-----------+----------+
| 3 | 1 | 1 | checked_in | John | Doe | 555-1234 |
+------------+----------+---------+------------+------------+-----------+----------+

SELECT name, class, section, contact_number


FROM academic_info, student_details
WHERE academic_info.student_id = student_details.student_id
AND academic_info.class < 12;

output:
+---------------+-------+---------+----------------+
| name | class | section | contact_number |
+---------------+-------+---------+----------------+
| John Doe | 10 | A | 555-1234 |
| Alice Brown | 11 | C | 555-8765 |
| Bob Johnson | 9 | A | 555-4321 |
| Charlie Davis | 10 | B | 555-1111 |
+---------------+-------+---------+----------------+

SELECT name, class, section, contact_number


FROM academic_info, student_details
WHERE academic_info.student_id = student_details.student_id
AND name like 'B%';

output:
+-------------+-------+---------+----------------+
| name | class | section | contact_number |
+-------------+-------+---------+----------------+
| Bob Johnson | 9 | A | 555-4321 |
+-------------+-------+---------+----------------+

You might also like