ST ANDREWS PUBLIC SCHOOL CS
ST ANDREWS PUBLIC SCHOOL CS
SESSION=2024-25
A Report File
On
The Text File , Binary File , CSV File , SQL
Queries
S NO. TOPIC
1. Binary File
2. Text File
3. CSV Files
4. SQL Queries
5. SQL Connectivity
PHYTHON PROGRAMS
1. write a function that take two no and returns
the number that has minimum ones digit.
Coding
output:
2. write a function namely nth root () that
receives two parameters x and n and returns nth
root of x I.e x*l/n The default value of n is 2.
Coding
output:
3. write a method that take a filename and display
the longest line from the file.
Coding
output:
4. write a method that take file name with
extensions and create a new file in which line
that begins with capita/ are inserted.
Coding
output:
Let us consider using this file Poem.Txt
there will be some following programs:
5. write a program that print the line of text file
poem. txt with line no.
Coding
output:
6. write a program that print the data from csv file in
the form of table.
Coding
output:
7. write a program that read a text file and creates
another file that is identical except that every
sequence of consecutive blank spaces is replaced by
a single space.
Coding
output:
8. write a method disp/aywords() in python to read
the lines from poem. txt and display those words
which are less than 4 characters.
Coding
output:
9.write a program that count no of to and To
present in poem. txt
Coding
output:
10. write a program to create a csv file op. csv
containing s.no,name,age.
Coding:
Output:
Op. csv:
11.Write a program to implement stack to enter
marks of students and perform push and display
operator with the help of stack.
Coding:
Output:
12. write a program to implement stack to
perform push and display operation. The stack
contain rollno and marks of student.
Coding:
Output:
13. write a program to implement stack that
contains the information of book details ,book
no,book name to perform pop and display
operations.
Coding:
Output:
14.write a program to implement stack to perform
push and pop operation . The stack contain the
information of employ (id,name,posts).
Coding:
Output
15. write a program with the help of stack
of even no with 70 elements input only
those element which are divisible by 2. Just
implement push and display options.
Coding:
Output
SQL Query regarding Table
• 1. From the following tables, write a SQL query to find the
salespeople and customers who live in the same city. Return
customer name, salesperson name and salesperson city.
The Kashmir
M001 Action 2022/01/26 1245000 1300000
Files
Shabaash
M005 Biography 2022/02/04 1000000 800000
Mithu
Output:
Answers:
[1] select pow(5,3);
[2] select round(563.854741, -2);
1. Display the match id, team id, team score who scored more than
70 in first inning along with team name.
2. Display match id, team name and second team score between
100 to 160.
3. Display match id, team names along with match dates.
4. Display unique team names
5. Display match id and match date played by Aadhi and Shailab.
Answers:
Answers:
OUTPUT:
PROGRAM 2:
Write a program to connect python with mysql using
database connectivity and perform the following
operations in database:
a) Display all the records of students who are in Medical
stream
b) b) Change the Class of Divakar to 12C
c) c) Display the maximum mark of 12B students
SOURCE CODE:
import mysql.connector
# Establish a connection to the MySQL server
mycon=mysql.connector.connect(
host='localhost’,
user='root’,
password='password’,
database='School')
if mycon.is_connected():
print('Database connected')
cursor = mycon.cursor()
# a) Display all the records of students who are in the
Medicalstream
sql ="SELECT * FROM STUDENT WHERE Stream='Medical’”
cursor.execute(sql)
records =.fetchall()
print("Answer for a):")
for recin records.
print(rec)
# b) Change the Class of Divakar to 12C
sql = "UPDATE STUDENT SET Class='12C' WHERE
Name='Divakar’”
cursor.execute(sql)
mycon.commit()
print("Record Updated")
SOURCE CODE:
import mysql.connector
# Establish a connection to the MySQL server
mycon=mysql.connector.connect(
host='localhost’,
user='root’,
password='password’,
database='School’)
if mycon.is_connected():
print('Database connected’)
# Create a cursor object
cursor = mycon.cursor()
# a) Count the number of records in each stream and display it
sql ='SELECT Stream, COUNT(*) FROM STUDENT GROUP BY
Stream’
cursor.execute(sql)
data = cursor.fetchall()
print("Answer for a):")
for recin data:
print(rec)
# b) Display the number of students who have secured 'A' Grade
sql ="SELECT COUNT(*) FROM STUDENT WHERE Grade='A’”
cursor.execute(sql)
count = cursor.fetchone()[0]
print("The number of students with 'A' grade is {count}")
# c) Add a new column called Rank in the table.
sql ='ALTER TABLE STUDENT ADD Rank CHAR(3)’
cursor.execute(sql)
mycon.commit()
print('Field Added’)
# Close the connection
mycon.close()
OUTPUT