Practical File
Practical File
Practical File
Computer Science
Python and RDBMS
Practical File
Session: 2023-24
Teacher: ________________
Examiner: _______________
Principal: _______________
Acknowledgement
I, Divyansh Raj Kureel of class XII comm., would like to
express my sincere gratitude to my computer science
teacher Mr. Priyanshu Gautam, for his vital support,
guidance and encouragement – without which this project
would not have come forth.
I would also like to express my gratitude to my school
Bhonwal Convent School for letting me use the school
laboratory.
Coding:
Output:
2. Write a program to know the cursor position and print the text according to the given
specifications:
Coding:
Output:
3. Write a program to read a file named “article.txt”; count and print the following:
Output:
b. . Total alphabets
Coding:
Output:
Output:
d . Total lowercase alphabets
Coding:
Output:
e . Total digits
Coding:
Output:
f . Total spaces
Coding:
Output:
g. Total special characters
Coding:
Output:
4. Write a program to read a file named “idiom.txt”;count and print total words starting with “e” or
“E” in the file. (idiom.txt stores: ‘Every cloud has a silver lining’)
Coding:
Output:
5. Write a function that makes a list and returns a new list with unique elements of the first list.
Coding:
Output:
6. Write a function to count the number of uppercase alphabets present in a text file “Practical.txt”.
(Practical.txt stores: ‘This is Class 12 Computer Science Practical File’)
Coding:
Output:
7. Write a program to search for a record to “data.csv” according to the empid input from the user.
Structure of the record saved in “data.csv” is empid, emp_name, dept, salary.
Coding:
Output:
8. Write a program to copy the data from “data.csv” to “temp.csv”. (Assume data in data.csv file)
Coding:
Ouput:
9. Write a program to show the details of the famous quotes stored in the csv file “quotes.csv”
using writerows() function. Data stored in the “quotes.csv” is given below:
Coding:
Output:
10. Write a program to write the following rows and fields in a csv file.
#Field names
Fields=[‘Name’,’Branch’,’Year’,’CGPA’]
#data rows of csv file
rows = [[‘Shyam’,’COE’,’2’,’9.0’],
[‘Garima’,’COE’, ‘2’, ‘9.1’],
[‘Sandeep’, ‘IT’, ‘2’, ‘9.3’],
[‘Chandan’, ‘SE’, ‘1’, ‘9.5’],
[‘Prateek’, ‘IT’, ‘3’, ‘9.8’],
[‘Priyanka’, ‘EP’, ‘2’, ‘9.8’]]
Coding:
Output:
11. Write a menu driven program to maintain book details like book code, book title, and price using
stacks.[Implement push(), pop(), and traverse() functions]
Coding:
Output:
12. Write a function push(number) to add a number (accepted from the user) and pop(number) and
remove a number from a list of numbers, considering them to act as PUSH and POP operations
of the stack data structure.
Coding:
Output:
13. Write a function push() which takes “name” as argument and adds it in a stack names ”MyStack”.
After calling push() three times, a message should be displayed “Stack is Full”.
Coding:
Output:
14. Write add(bookname) and delete() method to add and remove a bookname respectively
considering them to act as push() and pop() operations in a stack.
Coding:
Output:
15. Write a program in Python to read file "story.txt" and copy only those lines to "data.txt" which
are starting from alphabets "A" or "T".
Coding:
Output:
RDBMS – MySQL
Queries
16. Create a table Student and insert data in it. Implement the following SQL commands on the
student table:
a. ALTER table to add new attributes /modify data type/ drop attribute
e . GROUP BY and find the min, max, sum, Count and average
SELECT
MIN(enroll_no)AS min_age,
MAX(enroll_no) AS max_age,
SUM(enroll_no) AS total_age,
COUNT(*) AS total_students,
AVG(enroll_no) AS avg_age
FROM student;
Python Connection
Interface
17. Write a function to insert a record in a table in MySQL using Python interface
Coding:
Output:
18. Write a function to search a record stored in a table in MySQL using Python interface.
Coding:
Output:
19. Write a program to connect Python with MySQL using database connectivity and perform the:
Output:
b. Update operations on the data in the database.
Coding:
Output: