0% found this document useful (0 votes)
26 views

Practical File Computer Science 2024-25

The document outlines a series of practical programming exercises primarily focused on Python and SQL. It includes tasks such as determining if a number is prime, calculating factorials, manipulating text files, and performing database operations using MySQL. Additionally, it covers the implementation of data structures like stacks and the integration of Python with MySQL for database management.

Uploaded by

sonakshiiverma74
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Practical File Computer Science 2024-25

The document outlines a series of practical programming exercises primarily focused on Python and SQL. It includes tasks such as determining if a number is prime, calculating factorials, manipulating text files, and performing database operations using MySQL. Additionally, it covers the implementation of data structures like stacks and the integration of Python with MySQL for database management.

Uploaded by

sonakshiiverma74
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

INDEX

Sr. PRACTICAL

1. PROGRAM TO FIND WHETHER THE ENTERED NUMBER IN PRIME OR NOT.


2. PROGRAM TO FIND FACTORIAL OF A NUMBER ENTERED BY USER.
3. PROGRAM TO REVERSE A NUMBER ENTERED BY USER.

4. WRITE A PROGRAM TO SEARCH FOR A GIVEN NUMBER IN A LIST.


5. WRITE A PROGRAM TO CREATE A DICTIONARY WITH ROLL NUMBER AS KEY AND NAME AS
VALUES AND THEN DISPLAY ONLY THOSE NAMES WHICH ARE STARTING WITH THE ALPHABET
A.
6. CREATE A MENU DRIVEN CODE FOR PERFORMING ARITHMETIC OPERATION.
7. WRITE A PROGRAM TO CREATE FIBONACCI SERIES.
8. TO WRITE A PYTHON PROGRAM TO DEFINE THE FUNCTION CHECK(NO1,NO2) THAT
TAKE TWO NUMBERS AND RETURNS THE NUMBER THAT HAS MINIMUM ONES DIGIT.

9. WRITE A PROGRAM TO SHOW THE USE OF GLOBAL KEYWORD IN THE FUNCTION.


10. TO WRITE A PYTHON PROGRAM TO GENERATE RANDOM NUMBER BETWEEN 1
TO 6 TO SIMULATE THE DICE.
11. TO WRITE A PYTHON PROGRAM TO READ A TEXT FILE "STORY.TXT" LINE BY LINE
AND DISPLAY EACH WORD SEPARATED BY '#'.
12. TO WRITE A PYTHON PROGRAM TO READ A TEXT FILE "SAMPLE.TXT" AND
DISPLAYS THE NUMBER OF VOWELS/ CONSONANTS/ LOWERCASE /
UPPERCASE/CHARACTERS IN THE FILE.
13. WRITE A PROGRAM TO READ DATA FROM A TEXT FILE AND WRITE ALL THE LINE INTO A NEW
FILE WHICH ARE HAVING ALPHABET A IN THEM.
14. WRITE A PROGRAM TO CREATE A BINARY FILE OF 5 STUDENTS WITH RN AND NAME. AND
SEARCH THE RN AND DISPLAY APPROPRIATE MESSAGE WHEN ROLL FOUND AND NOT FOUND
ALSO DISPLAY THE NAME OF ROLL NUMBER IF FOUND.
15. PROGRAM TO UPDATE THE DATA IN A BINARY FILE.
16. CREATE A CSV FILE BY ENTERING USER-ID AND PASSWORD, READ AND SEARCH THE
PASSWORD FOR GIVEN USERID.
17. ROGRAM TO IMPLEMENT STACK USING LIST

18. SQL COMMANDS EXERCISE – 1


19. SQL COMMANDS EXERCISE – 2

20. SQL COMMANDS EXERCISE – 3


21. SQL COMMANDS EXERCISE – 4
22. SQL COMMANDS EXERCISE – 5
23. PYTHON MYSQL CONNECTIVITY PROGRAM - CREATING DATABASE & TABLE
24. PYTHON MYSQL CONNECTIVITY PROGRAM – INSERTING DATA IN TABLE
25. PYTHON MYSQL CONNECTIVITY PROGRAM – SELECTING DATA FROM TABLE

26. PYTHON MYSQL CONNECTIVITY PROGRAM – UPDATING FROM IN TABLE


27. PYTHON MYSQL CONNECTIVITY PROGRAM – LOGIN SYSTEM
Q1) Program to find whether the entered number in prime or not.

OUTPUT:-
Q2)Program to find factorial of a number entered by user.

Output:-
Q3) Program to reverse a number entered by user.

Output:-
Q4) Write a program to search for a given number in a list.

Output:-
Q5) Write a program to create a dictionary with roll number as key and name as values and then display only
those names which are starting with the alphabet A.

Output:-
Q6) Create a menu driven code for performing arithmetic operation.

Output:-
Q7) Write a program to create Fibonacci series.

Output:-
Q8) To Write a Python program to define the function Check(no1,no2) that take two numbers
andReturns the number that has minimum ones digit.

Output:-
Q9) Write a program to show the use of global keyword in the function.

Output:-

Function with global keyword

Output:-
Q10) To write a Python program to generate random number between 1 to 6 to
simulatethe dice.

Output:-
11) To write a Python Program to Read a text file "Story.txt" line by line and
displayeach word separated by '#'.

Output:-
Q12) To write a Python Program to read a text file "sample.txt" and displays the
number ofVowels/ Consonants/ Lowercase / Uppercase/characters in the file.

Output:-
Q13) Write a program to read data from a text file and write all the line into a new file which are having
alphabet a in them.
Q14) Write a program to create a binary file of 5 students with rn and name. And search the rn and display
appropriate message when roll found and not found also display the name of roll number if found.

Output:-
Q15) Program to update the data in a binary file.

Output:-
Q16) Create a CSV file by entering user-id and password, read and search the password for given userid.

Output:-
Q17) Program to implement stack using list
Output:-
Q18) Write SQL queries for the following questions –

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to Create a new database with name SCHOOL.

CREATE DATABASE SCHOOL;


(b) Write a Query to Open the database "SCHOOL".

USE SCHOOL;

(c) Write a Query to create the above table "STUDENT"

CREATE TABLE STU(ROLLNO INT PRIMARY KEY,NAME VARCHAR(10), GENDER


VARCHAR(3), AGE INT,DEPT VARCHAR(15), DOA DATE, FEES INT);

(d) Write a Query to list all the existing database names.

SHOW DATABASES;
(e) Write a Query to List all the tables that exists in the current database.

SHOW TABLES;
Q19) Write SQL queries for the following questions –

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to insert all the rows of above table into Info table.

INSERT INTO STUDENT VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);

INSERT INTO STUDENT VALUES (2,'Ankit','M', 21,'HISTORY','1998-03-24', 200);

INSERT INTO STUDENT VALUES (3,'Anu','F', 20,'HINDI','1996-12-12', 300);

INSERT INTO STUDENT VALUES (4,'Bala','M', 19, NULL,'1999-07-01', 400);

INSERT INTO STUDENT VALUES (5,'Charan','M', 18,'HINDI','1997-06-27', 250);

INSERT INTO STUDENT VALUES (6,'Deepa','F', 19,'HISTORY','1997-06-27', 300);

INSERT INTO STUDENT VALUES (7,'Dinesh','M', 22,'COMPUTER','1997-02-25', 210);

INSERT INTO STUDENT VALUES (8,'Usha','F', 23, NULL,'1997-07-31', 200);


(b) Write a Query to display all the details of the Employees from the above table 'STUDENT'.

SELECT * FROM STUDENT;

Output:

(c) Write a query to Rollno, Name and Department of the students from STUDENT table.

SELECT ROLLNO,NAME,DEPT FROM STUDENT;


(d) Write a Query to select distinct Department from STUDENT table.

SELECT DISTICT(DEPT) FROM STUDENT;

Output:

(e) To show all information about students of History department.

SELECT * FROM STUDENT WHERE DEPT='HISTORY';

Output:
Q20) Write SQL queries for the following questions –

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to list name of female students in Hindi Department.

SELECT NAME FROM STUDENT WHERE DEPT='HINDI' AND GENDER='F';

Output:

(b) Write a Query to list name of the students whose ages are between 18 to 20.

SELECT NAME FROM STUDENT WHERE AGE BETWEEN 18 AND 20;

Output:

(c) Write a Query to display the name of the students whose name is starting with 'A'.

SELECT NAME FROM STUDENT WHERE NAME LIKE 'A%';

Output:
(d) Write a query to list the names of those students whose name have second alphabet
'n' in theirnames.

SELECT NAME FROM STUDENT WHERE NAME LIKE '_N%';

Output:
Q21) Write SQL queries for the following questions –

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to delete the details of Roll number is 8.

DELETE FROM STUDENT WHERE ROLLNO=8;

Output (After Deletion):

(b) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the
existing fessis less than 130.

UPDATE STUDENT SET FEES=170 WHERE ROLLNO=1 AND FEES<130;

Output(After Update):
(c) Write a Query to add a new column Area of type varchar in table STU.

ALTER TABLE STUDENT ADD AREA VARCHAR(20);

Output:

(d) Write a Query to Display Name of all students whose Area Contains NULL.

SELECT NAME FROM STU WHERE AREA IS NULL;

Output:

(e) Write a Query to delete Area Column from the table STU.

ALTER TABLE STU DROP AREA;

Output:

(f) Write a Query to delete table from Database.

DROP TABLE STUDENT;

Output:
Q22) Write SQL queries for the following questions –

a) Write an sql query to display total student’s class wise.

SELECT CLASS,COUNT(*) FROM STUDENT GROUP BY CLASS;

b) Write an sql query to display total student’s gender wise.

SELECT GENDER,COUNT(*) FROM STUDENT GROUP BY GENDER;

c) Write an sql query to display the fees of sohan using natural join

SELECT FEES.FEES FROM STUDEN NATURAL JOIN FEES WHERE NAME=’SOHAN’;


d) Write an sql query to display the details of students whose name ends with n.

SELECT *FROM STUDENT WHERE NAME LIKE ‘%N’;

e) Write an sql query to display all the details along with the fees details using equi join.

SELECT *FROM STUDENT,FEES WHERE STUDENT.CLASS=FEES.CLASS;


Q23) To write a Python Program to integrate MYSQL with Python to create Database with name lib
and table book.

Output:-

Data initialized successfully


Q24) To write a Python Program to integrate MYSQL with Python to insert records
in library tables.

Output:-
Q25) To write a Python Program to integrate MYSQL with Python a n d d i s p l a y
the records present in the book table of lib database .

Output:-
Q26) To write a Python Program to integrate MYSQL with Python a n d u p d a t e t h e
bookname for the provided book number.

Output:-
Q27) To write a Python Program to integrate MYSQL with Python a n d c r e a t e a
login system.

Output:-

----------------END--------------

You might also like