0% found this document useful (0 votes)
122 views35 pages

Xii Cs Practical File kv2 2023-24

Here are the Python codes for SQL connectivity programs: 1. Connecting MySQL database to Python: ```python import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="mydatabase" ) ``` 2. Create table and show tables: ```python import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="school" ) mycursor = mydb.cursor() mycursor.execute("CREATE TABLE emp (name VARCHAR(255), salary

Uploaded by

Mentalist
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)
122 views35 pages

Xii Cs Practical File kv2 2023-24

Here are the Python codes for SQL connectivity programs: 1. Connecting MySQL database to Python: ```python import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="mydatabase" ) ``` 2. Create table and show tables: ```python import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="school" ) mycursor = mydb.cursor() mycursor.execute("CREATE TABLE emp (name VARCHAR(255), salary

Uploaded by

Mentalist
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/ 35

12-Computer Science

Practical File, 2023-24


INDEX
S. NO. OBJECTIVE
1. Write a python program to search an element in a list and display the frequency of element present in
list and their location using Linear search by using user defined function.
[List and search element should be entered by user]
2. To write a python program to pass list to a function and double the odd values and half even values of
a list and display list element after changing.
3. To write a Python program input n numbers in tuple and pass it to function to count how many even
and odd numbers are entered.
4. To write a Python program to function with key and value, and update value at that key in dictionary
entered by user.
5. To write a Python program to generator (Random Number) that generates random numbers between
1 and 6 (simulates a dice) using user defined function.
6. To write a python program to implement python string functions.
7. To write a python program to read and display text file content line by line with each word separated
by #.
8 To write a python program read a text file and display the number of vowels, consonants, uppercase
and lowercase consonants in a text file.
9 To write a python program to count spaces, digits, words and lines from text file
10 To write a python program to remove all the lines that contain the character “a‟ in a file and write it to
another file
11 To write a python program to create a binary file with name and roll number. Search for a given roll
number and display name, if not found display appropriate message.
12 Consider a binary file "student.dat" containing details such as rollno, name and marks. Write a python
program to search for a given roll number in a binary file and update the name.
13 Consider a binary file "student.dat" containing details such as rollno, name and marks. Write a python
program to display details of those students who secured more than 70 marks.
14 To write a python program to create employee.csv file and store empno, name and salary then search
for a particular empno to display name and salary.
15 To write a python program to add and delete an element in stack.
Practical 1
Aim:Write a python program to search an element in a list and
display the frequency of element present in list and their location
using Linear search by using user defined function. [List and
search element should be entered by user]

Code:

Output :
Practical 2
Aim:To write a python program to pass list to a function and
double the odd values and half even values of a list and display
list element after changing.

Code:

Output :
Practical 3
Aim:To write a Python program input n numbers in tuple and
pass it to function to count how many even and odd numbers are
entered.

Code:

Output :
Practical 4
Aim:To write a Python program to function with key and
value, and update value at that key in dictionary entered by user.

Code:

Output :
Practical 5
Aim:To write a Python program to generator (Random
Number) that generates random numbers between 1 and 6
(simulates a dice) using user defined function.

Code:

Output :
Practical 6
Aim:To write a python program to implement python string
functions.

Code:
Output:
Practical 7
Aim: To write a python program to read and display text
file content line by line with each word separated by #.

Code:
Text File used:

Output:
Practical 8
Aim: To write a python program read a text file and display the
number of vowels, digits, consonants, uppercase, lowercase
consonants in a text file.

Code:
Text file used:

Output:
Practical 9
Aim: To write a python program to count spaces, digits, words
and lines from text file.

Code:
Text file used:

Output:
Practical 10
Aim: To write a python program to remove all the lines that
contain the character “a‟ in a file and write it to another file.

Code:
Text file used:

Output:

Output Text File Produced:


Practical 11
Aim: To write a python program to create a binary file with
name and roll number. Search for a given roll number and display
name, if not found display appropriate message.

Code:
Output :
Practical 12
Aim: Consider a binary file "student.dat" containing details
such as rollno, name and marks. Write a python program to
search for a given roll number in a binary file and update the
name.

Code:
Output :
Practical 13
Aim: Consider a binary file "student.dat" containing details
such as rollno, name and marks. Write a python program to
display details of those students who secured more than 70
marks.

Code:
Output :
Practical 14
Aim: To write a python program to create employee.csv file
and store empno, name and salary then search for a particular
empno to display name and salary.

Code:
Output :

CSV File Produced:


Practical 15
Aim: To write a python program to add and delete an element
in stack.

Code:
Output:
1
SQL QUERIES
Write MySQL command to create a database SCHOOL.

2 Write MySQL command to open the database SCHOOL

3 Write MySQL command to create a table ‘student’ with the following attributes:
rollno, name, class, gender, dob and marks.
Set rollno as primary key.

4 Write MySQL command to describe structure of table student.


5 Write MySQL command to insert records in table student.

6 Write MySQL command to display all the records of table student.

7 Write MySQL command to display name and class of all male students.

8 Write MySQL command to display name and class of male students of class 12.
9 Write MySQL command to display total marks of students studying in class 12.

10 Write MySQL command to display records of student table in ascending order of their marks.

11 Write MySQL command to display name, class and marks of students of class 11 in descending
order of their marks.
12 Write MySQL command to display number of students in each class.

13 Write MySQL command to display average marks, minimum marks and maximum marks obtained
by student gender wise.

14 Write MySQL command to display name and marks of students whose name start with character
‘s’ .
15 Write MySQL command to display name and marks of students whose marks are between 70 and
80.

16 Write MySQL command to display name and class of students whose marks is NULL.

17 Write MySQL command to display unique classes of student table.

18 Write MySQL command to increase the marks of all student by 10 who born in year 2004.
19 Write MySQL command to remove the records of those students who scored less than 60 marks.

20 Write MySQL command to add a new column city with appropriate data type in student table.
SQL Connectivity Programs
1 Write python code to establish a connection between mySQLdb and Python.

2 Write python code to create table emp in school database and showing existing table names
3 Write python code to display records of table emp from school database

4 Write python code to update records in table emp of school database


5 Write python code to display records of table emp from school database (parameterized query
concatenating dynamic variable with query in which values entered)

You might also like