Rishabh Programss
Rishabh Programss
CERTIFICATE
This is To certify that this is to certify
that RISHABH KUMAR of 12th of CPS
International School has completed his
report file under my supervision he has
completed the report file work
independently and has shown utmost
sincerity in completion of this file.
This report file fully implements all the
topics and concept done in Python And
MySQL covered in class 11th and 12th
as per the CBSE syllabus of computer
science subject.
I certify that this practical file is up to
my expectation and as per guidelines
issued by CBSE.
ACKNOWLEDGEMENT
I would like to take this opportunity to
extend my sincere gratitude and
appreciation to my computer lab
teacher Mrs. DEEPTI AGGARWAL for
providing guidance and support
throughout the process of completing
my computer project for school.
I am also thankful to my principal Mrs.
MEENAKSHI PADHY for allowing me the
opportunity to explore and work on this
project in the school environment.
Additionally, I would like to express my
heartfelt thanks to my family for their
unwavering support and
encouragement during the completion
of this project.
3
RISHABH KUMAR
XII A (SCIENCE)
INDEX
PARTS TITTLE
1. PROGRAM 1
PROGRAM 2
PROGRAM 3
PROGRAM 4
PROGRAM 5
PROGRAM 6
PROGRAM 7
PROGRAM 8
PROGRAM 9
PROGRAM 10
PROGRAM 11
PROGRAM 12
PROGRAM 13
PROGRAM 14
PROGRAM 15
2 QUESTION 1
QUESTION 2
QUESTION 3
QUESTION 4
QUESTION 5
4
3 QUESTION 1
QUESTION 2
QUESTION 3
QUESTION 4
def Push3_5(N):
"""
This function accepts a list of integers N,
and pushes all integers divisible by 3 or 5 into a list named Only3_5.
Args:
N (list): A list of integers.
Returns:
list: A list of integers divisible by 3 or 5.
"""
Only3_5 = []
for num in N:
if num % 3 == 0 or num % 5 == 0:
Only3_5.append(num)
return Only3_5
numbers = [1,2,3,4,5,6,7,8,9,10,11,1,12]
result = Push3_5(numbers)
print(result)
output:
RESTART:
C:/Users/rishabh/AppData/Local/Programs/Python/Python311/python
1.py
[3, 5, 6, 9, 10, 12]
5
6
# This function will filter the integers from NUM that are either 3 or 5
Only3_5 = []
if num == 3 or num == 5:
Only3_5.append(num)
return Only3_5
NUM = []
for i in range(5):
NUM.append(num)
Only3_5 = Push3_5(NUM)
while Only3_5:
popped_value = Only3_5.pop()
if not Only3_5:
print("\nStackEmpty")
OUTPUT:
Enter an integer: 10,6,14,18,30RESTART:
C:/Users//AppData/Local/Programs/Python/Python311/ 1.py
[3, 5, 6, 9, 10, 12]
7
def Sum3(L):
# Initialize the sum variable to 0
total_sum = 0
# Iterate through each integer in the list
for num in L:
# Check if the last digit of num is 3
if num % 10 == 3:
total_sum += num # Add num to the total sum
# Display the sum
print(f"Sum of integers ending with digit 3 =
{total_sum}")
# Example usage:
Sum3([123, 10, 13, 15, 23])
OUTPUT:
RESTART:
C:/Users//AppData/Local/Programs/Python/Python311/
Sum of integers ending with digit 3 = 159
8
def Count_Line():
# Initialize a counter to keep track of the number of
lines
line_count = 0
# Open the file "SHIVAJI.TXT" in read mode
try:
with open("SHIVAJI.TXT", "r") as file:
# Loop through each line in the file
for line in file:
# Increment the line count for each line read
line_count += 1
# Display the total number of lines
print(f"Total number of lines: {line_count}")
except FileNotFoundError:
print("The file 'SHIVAJI.TXT' was not found.")
#EXAMPLE: Shivaji was born in the family of Bhonsle.He
was devoted to his mother Jijabai.India at that time was
under Muslim rule.
OUTPUT:
C:\Users\\AppData\Local\Programs\Python\Python311\
PYTHON 3.py
Total number of lines : 3
9
# Example usage
file_path = 'your_file.txt' # Replace with your file path
result = count_lines_starting_with_k(file_path)
print(f"Number of lines starting with 'K': {result}")
OUTPUT:
RESTART: C:\Users\\AppData\Local\Programs\Python\
Python311\ python4.py
Number of lines starting with 'K': 4
Output :
RESTART:C:\Users\Gunjan\AppData\Local\Programs\
Python\Python311\rishabh python4.py
Total alphabets in the file: 56
12
self.book_code = book_code
self.book_title = book_title
self.price = price
def _str_(self):
class BookStack:
def _init_(self):
self.stack = []
self.stack.append(book)
def pop(self):
if len(self.stack) == 0:
else:
return self.stack.pop()
def traverse(self):
if len(self.stack) == 0:
else:
print("Books in stack:")
print(book)
if _name_ == "_main_":
book_stack = BookStack()
book_stack.traverse()
popped_book = book_stack.pop()
print(f"Popped: {popped_book}")
book_stack.traverse()
while True:
popped_book = book_stack.pop()
if popped_book is None:
break
print(f"Popped: {popped_book}")
OUTPUT:
*Books in stack:
Book Code: B002, Title: Data Structures and Algorithms, Price: 499.99
Popped: Book Code: B003, Title: Machine Learning Basics, Price: 699.99
Book Code: B002, Title: Data Structures and Algorithms, Price: 499.99
Popped: Book Code: B002, Title: Data Structures and Algorithms, Price: 499.9
def fibonacci(n):
if n <= 0:
elif n == 1:
return 0
elif n == 2:
return 1
else:
def display_fibonacci_sequence(count):
print("Fibonacci Sequence:")
try:
if n_terms > 0:
display_fibonacci_sequence(n_terms)
else:
except ValueError:
OUTPUT:
RESTART: C:\Users\Gunjan\AppData\Local\Programs\Python\Python311\
rishABH PYTHON 2.py
Fibonacci Sequence:
0 1 1 2 3 5 8
15
def is_armstrong(number):
num_str = str(number)
num_digits = len(num_str)
try:
if is_armstrong(num):
else:
else:
except ValueError:
OUTPUT:
RESTART: C:\Users\\AppData\Local\Programs\Python\Python311\
rishABH PYTHON 2.py
Enter a number: -5
if operator == '+':
if num2 != 0:
else:
else:
try:
print(f"Result: {result}")
except ValueError:
OUTPUT:
RESTART: C:\Users\Gunjan\AppData\Local\Programs\Python\Python311\rishABH
PYTHON 2.py
Result: 15.0
17
return num1
return num2
else:
return num3
try:
except ValueError:
OUTPUT:
RESTART: C:\Users\Gunjan\AppData\Local\Programs\Python\Python311\
rishABH PYTHON 2.py
PROGRAM 13: Read a text file and display the number of vowels/
consonants /uppercase/ lowercase characters in the file.
def analyze_file(filename):
try:
text = file.read()
vowels = "aeiouAEIOU"
vowel_count = 0
consonant_count = 0
uppercase_count = 0
lowercase_count = 0
if char.isalpha():
if char in vowels:
vowel_count += 1
else:
consonant_count += 1
if char.isupper():
uppercase_count += 1
elif char.islower():
lowercase_count += 1
print("File Analysis:")
print(f"Vowels: {vowel_count}")
print(f"Consonants: {consonant_count}")
except FileNotFoundError:
except Exception as e:
analyze_file(filename)
19
OUTPUT:
RESTART: C:\Users\Gunjan\AppData\Local\Programs\Python\Python311\rishABH
PYTHON 2.py
Vowels: 1134
Consonants: 2356
import csv
def write_to_csv(filename):
records = []
while True:
if student_id.lower() == 'stop':
break
records.append({
'ID': student_id,
'Username': username,
'Balance': balance })
try:
writer.writeheader()
writer.writerows(records)
except Exception as e:
filename = 'student.csv'
write_to_csv(filename)
OUTPUT:
RESTART: C:\Users\Gunjan\AppData\Local\Programs\Python\Python311\rishABH
PYTHON 2.py
ID,Username,Account Number,Balance
101,Alice,12345678,5000
102,Bob,87654321,7500
22
class Stack:
def __init__(self):
self.stack = []
self.stack.append(item)
def pop(self):
if not self.is_empty():
item = self.stack.pop()
else:
def peek(self):
if not self.is_empty():
else:
def display(self):
if not self.is_empty():
print(element)
else:
print("Stack is empty.")
def is_empty(self):
return len(self.stack) == 0
def menu():
print("1. Push")
print("2. Pop")
23
print("3. Peek")
print("4. Display")
print("5. Exit")
# Main program
stack = Stack()
while True:
menu()
try:
if choice == 1:
stack.push(element)
elif choice == 2:
stack.pop()
elif choice == 3:
stack.peek()
elif choice == 4:
stack.display()
elif choice == 5:
break
else:
except ValueError:
OUTPUT:
RESTART: C:\Users\Gunjan\AppData\Local\Programs\Python\Python311\rishABH
PYTHON 2.py
1. Push
2. Pop
3. Peek
4. Display
24
5. Exit
10 pushed to stack.
1. Push
2. Pop
3. Peek
4. Display
5. Exit
20 pushed to stack.
1. Push
2. Pop
3. Peek
4. Display
5. Exit
20
10
1. Push
2. Pop
3. Peek
4. Display
5. Exit
1. Push
2. Pop
3. Peek
4. Display
5. Exit
PART – 2
DATA STRUCTURE AND SQL QUERIES .
QUESTION 1 : Consider the following MOVIE table write the SQL
queries based on it,
c) display ID, movie cost and revenue by the movies. Calculate the profit
Using cost and revenue.
d) display ID, movie and cost for all movies with cost greater than 150 and
less than 1000.
f) display the list of movies which are going to release in February, 2023
ANSWERS:
ANS (A):
ANS(B):
27
ANS(C):
ANS(D)
ANS(E)
ANS(F)
28
QUESTION 2
PID PNAME AGE DEPARTMEN DATE OF CHARGE GENDER
T ADM S
1 KARAN 34 CARDIAC 2022-12- 550.00 M
02
2 MUKTA 15 WOMEN 2022-11- 2640.00 F
20
3 HARSHIT 22 MEN 2022-10- 2750.00 M
19
4 SUMAN 15 WOMEN 2022-08- 3080.00 F
11
5 AMIT 34 ORTHOPEDI 2022-11- 880.00 M
C 11
6 ALKA 41 CARDIAC 2022-05- 2069.00 F
20
7 RAKESH 42 MEN 2022-06- 1430.00 M
18
ANS(A)
ANS(B)
ANS(C)
29
ANS(D)
30
QUESTION 3
Q: Suppose your school management has decided to conduct
cricket matches between students of clas XI and class XII.Students
of each class are asked to join any one of the four teams – team
titan,team rockers,team magnet and team huricane.during summer
vacations , various matches will be conducted between these
teams.help your sports teacher to do the following:
ii)Each teamID should have its associated name (team name) which
should be a string of length not less than 10 characters.
D)As per the prefrences of the students four teams were formed as given
below , insert these four rows in TEM table.
i) ROW 1 :(1,RED)
ii)ROW 2:(2,GREEN)
iii)ROW 3:(3,YELLOW)
iv)ROW 4:(4,BLUE)
ANWERS:
31
32
QUESTION 4:
Q: Write the following queries:
ANWERS:
33
QUESTION 5:
Q - Consider the following table (table name: stock) and write the queries:
ANWERS:
(A)
(B)
34
(C)
(D)
(E)
35
PART – 3
PYTHON DATABASE
CONNECTIVITY
QUESTION 1: Write a MySQL connectivity program in Python to a create a
database school b .create a table student with specification-Roll number
integer, St name character (10) in MySQL and perform the following
operations:
import mysql.connector
mycursor mydb.cursor()
mycursor.execute("USE school")
mydb.commit()
value mycursor.fetchall()
for i in value:
RESULTS:
(I)
(II)
36
37
QUESTION 2:
Q- Perform all the operations with reference to table “students” through MySQL
connectivity. (insert, update, delete):
import mysql.connector
mycursor mydb.cursor()
def main()
while True:
print("1. Insertion")
print("2. Update")
print("3. Delete")
print("4. Exit")
try:
continue
if choose == 1:
try:
continue
mydb.commit()
elif choose 2:
try:
continue
data (roll_no,name.old_roll_no)
%s)" data)
mydb.commit()
try:
continue
data = ((roll_no).)
mydb.commit()
elif choose== 4
break
else:
continue
if_name_==”_main_”:
RESULT:
39
QUESTION 3:
40
Q- Write a menu- driven program to store data into a MySQL table customer as
following :
Import mysql.connector
Mycursor = mydb.cursor()
Def main()
Initiate()
while True
print(“5.exit “)
try:
choose= int(input(“input:”))
except(valueerror,type error)
continue
if choose== 1
try:
name= input("Name”)
city=input(“city”)
continue
data = (name,bill,city,category)
mydb.commit()
41
elif choose == 2
try:
c_id = int(input“id:”))
name=input(“new name:”)
except (valueerror,typeerror):
Continue
Data=(name,bill,city,category,c_id)
Mydb.commit()
Try:
C_id = int(input(“customerid:”))
Except (valueerror,typeerror)
continue
data=((c_id))
mydb.commit()
elif choose == 4:
values = mycursor.fetchall()
print(value)
elif choose==5:
break
else:
continue
42
try:
mycursor.execute(“use shop”)
except:
mycursor.execute(“use shop”)
if_name_==”_main_”:
main()
RESULTS:
43