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

Aman Final CS

Uploaded by

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

Aman Final CS

Uploaded by

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

CERTIFICATE

……………………….. ………………………….
Internal Examiner External Examiner
ACKNOWLEDGEMENT
TABLE OF CONTENTS
Practical Program – 1
CREATING A MENU DRIVEN PROGRAM TO PERFORM ARITHMETIC
OPERATIONS
AIM:
To write a menu driven Python Program to perform Arithmetic operations (+, -*, /)
Based on the user’s choice.

Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
successfully.

1
Sample output:

2
Practical Program – 2
CREATING A PYTHON PROGRAM TO DISPLAY FIBONACCI SERIES

AIM:
To write a Python Program to display Fibonacci Series up to ‘n’ numbers.
Source code-:

Result: Thus, the above Python program has been executed and the output is verified
successfully.

3
Sample Output:

4
Practical Program – 3
CREATING A MENU DRIVEN PROGRAM TO FIND FACTORIAL AND SUM OF
LIST OF NUMBERS USING FUNCTION.
AIM:
To write a menu driven Python Program to find Factorial and sum of list of numbers
Using function.

Source code-:

Result: Thus, the above Python program has been executed and the output is
verified successfully.

5
Sample Output:

6
Practical Program – 4
CREATING A PYTHON PROGRAM TO IMPLEMENT RETURNING VALUE(S)
FROM FUNCTION

AIM:
To Write a Python program to define the function Check (no1, no2) that take two
Numbers and Returns the number that has minimum one’s digit
Source code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully.

7
Sample Output:

8
Practical Program – 5
CREATING A PYTHON PROGRAM TO IMPLEMENT MATHEMATICAL
FUNCTIONS
AIM:
To write a Python program to implement python mathematical functions to
find:
1. To find Square of a Number.
2. To find Log of a Number (i.e. Log10)
3. To find Quad of a Number
Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully.

9
Sample Output:

10
Practical Program – 6
CREATING A PYTHON PROGRAM TO GENERATE RANDOM NUMBER
BETWEEN 1 TO 6
AIM:
To write a Python program to generate random number between 1 to 6 to simulate
the dice.

Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully.

11
Sample Output:

12
Practical Program – 7
CREATING A PYTHON PROGRAM TO READ A TEXT FILE AND DISPLAY
THE NUMBER OF VOWELS/CONSONANTS/LOWER CASE/ UPPER CASE
CHARACTERS.

AIM:
To write a Python Program to read a text file "Story.txt" and displays the number of Vowels/
Consonants/ Lowercase / Uppercase/characters in the file. Vowels/ Consonants/ Lowercase /
Uppercase/characters in the file.

Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully.

13
Sample Output:
Story.txt

Python output:

14
Practical Program – 8

CREATING A PYTHON PROGRAM TO READ A TEXT FILE LINE BY LINE


AND DISPLAY EACH WORD SEPARATED BY '#'

AIM:
To write a Python Program to Read a text file "Story.txt" line by line and display
Each word separated by '#'.

Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully.

15
Sample Output:
Story.txt

16
Practical Program – 9
CREATING PYTHON PROGRAM TO DISPLAY SHORT WORDS FROM A
TEXT FILE
AIM:
To Write a method Disp () in Python, to read the lines from poem.txt and display
Those words which are less than 5 characters.
Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully.

17
Sample Output:
Poem.txt

18
Practical Program – 10

CREATING A PYTHON PROGRAM TO COPY PARTICULAR LINES OF A


TEXT FILE INTO AN ANOTHER TEXT FILE

AIM:

To write a python program to read lines from a text file "Sample.txt" and copy those
Lines into another file which are starting with an alphabet 'a' or 'A'.

Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully.

19
Sample Output:
Sample.txt

Python Executed Program Output:

New.txt

20
Practical Program – 11
CREATING A PYTHON PROGRAM TO CREATE AND SEARCH RECORDS IN
BINARY FILE

AIM:
To write a Python Program to Create a binary file with roll number and name.
Search for a given roll number and display the name, if not found display
Appropriate message.

Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully.

21
Sample Output:

22
Practical Program – 12
CREATING A PYTHON PROGRAM TO CREATE AND UPDATE/MODIFY
RECORDS IN BINARY FILE

AIM:
To write a Python Program to Create a binary file with roll number, name, mark and
Update/modify the mark for a given roll number.
Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully. 23
Sample Output:

24
Practical Program – 13
CREATING A PYTHON PROGRAM TO CREATE AND SEARCH EMPLOYEE’S
RECORD IN CSV FILE.
AIM:
To write a Python Program Create a CSV file to store EMP no, Name, Salary and
Search any EMP no and display Name, Salary and if not found display appropriate
message.
Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
Successfully. 25
Sample Output:

26
CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS
(LIST)

AIM:
To write a Python program to implement Stack using a list data-structure, to perform the
following operations:
1. To push an object containing Doc_ID and Doc_name of doctors who specialize In
"ENT" to the stack.
2. To Pop the objects from the stack and display them.
3. To display the elements of the stack (after performing PUSH or POP
Source Code-:

27
Result: Thus, the above Python program has been executed and the output is verified
successfully.

28
29
CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS
(Dictionary)
AIM:
To write a program, with separate user-defined functions to perform the following
operations:
(i) Create a function Push (Stk,D) Where Stack is an empty list and D is Dictionary
Of Items. From this Dictionary push the keys (name of the student) into a stack,
where the corresponding value (marks) is greater than 70.
(ii) Create a Function Pop (Stk), where Stk is a Stack implemented by a list of
student names. The function returns the value deleted from the stack.
(iii) To display the elements of the stack (after performing PUSH or POP).
Source Code:

30
Result: Thus, the above Python program has been executed and the output is verified
successfully.

31
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(CREATING DATABASE AND TABLE)

AIM:
To write a Python Program to integrate MYSQL with Python to create Database and
Table to store the details of employees.
Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
successfully.

32
33
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(INSERTING RECORDS AND DISPLAYING RECORDS)
AIM:
To write a Python Program to integrate MYSQL with Python by inserting records to Emp
table and display the records.
Source Code-:

Result: Thus, the above Python program has been executed and the output is verified
successfully.

34
35
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(SEARCHING AND DISPLAYING RECORDS)

AIM:
To write a Python Program to integrate MYSQL with Python to search an Employee
Using EMPID and display the record if present in already existing table EMP, if not
display the appropriate message.
Source Code:

Result: Thus, the above Python program has been executed and the output is verified
successfully.

36
37
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(UPDATING RECORDS)
AIM:
To write a Python Program to integrate MYSQL with Python to search an Employee
using EMPID and update the Salary of an employee if present in already existing
table EMP, if not display the appropriate message.
Source Code:

Result: Thus, the above Python program has been executed and the output is verified
successfully.
38
39
To write Queries for the following Questions based on the given table:

(a) Write a Query to create a new database in the name of "STUDENTS"

Sol:mysql> CREATE DATABASE STUDENTS;

(b) Write a Query to open the database "STUDENTS"

Sol:mysql> USE STUDENTS;

(c) Write a Query to create the above table called: Info

Sol: mysql> 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.

Sol: mysql> SHOW DATABASES;

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

Sol: mysql> SHOW TABLES;

40
To write Queries for the following Questions based on the given table:

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

Sol: INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-


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

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

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

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

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

INSERT INTO STU VALUES (7,'Dinesh','M', 22,'COMPUTER','1997-02-25',


210);

INSERT INTO STU 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
'STU'.

Sol: mysql> SELECT * FROM STU;

41
(c) Write a query to Roll no, Name and Department of the students from STU table.

sol: mysql> SELECT ROLLNO,NAME,DEPT FROM STU;

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

Sol: mysql> SELECT DISTINCT (DEPT) FROM STU;

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

Sol: mysql>SELECT * FROM STU WHERE DEPT='HISTORY';

42
To write Queries for the following Questions based on the given table:

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

Sol: mysql> SELECT NAME FROM STU WHERE DEPT='HINDI' AND


GENDER='F';

(b) Write a Query to list name of the students whose ages are between 18 to 20.
Sol: mysql> SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20

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

Sol: mysql> SELECT NAME FROM STU WHERE NAME LIKE 'A%';

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

Sol: mysql> SELECT NAME FROM STU WHERE NAME LIKE '_N%';

44
To write Queries for the following Questions based on the given table:

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

Sol: mysql> DELETE FROM STU WHERE ROLLNO=8;

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

Sol: mysql> UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND


FEES<130;

45
(c) Write a Query to add a new column Area of type varchar in table STU.

Sol: mysql> ALTER TABLE STU ADD AREA VARCHAR(20);

(d) Write a Query to Display Name of all students whose Area Contains NULL
Sol: mysql> SELECT NAME FROM STU WHERE AREA IS NULL;

(e) Write a Query to delete Area Column from the table STU.
Sol: mysql> ALTER TABLE STU DROPAREA;

46
TABLE: STOCK

TABLE: DEALERS

To write Queries for the following Questions based on the given table:

(a) To display the total Unit price of all the products who’s Dcode as 102.
Sol: mysql> SELECT SUM (UNITPRICE) FROM STOCK WHERE
DCODE=102;

(b) To display details of all products in the stock table in descending order of Stock
date.

Sol: mysql> SELECT * FROM STOCK ORDER BY STOCKDATE DESC;

(c) To display maximum unit price of products for each dealer individually as per
dcode from the table Stock.

Sol: mysql> SELECT DCODE, MAX (UNITPRICE) FROM STOCK GROUP


BY DCODE;

(d) To display the Pname and Dname from table stock and dealers.

Sol: mysql> SELECT PNAME, DNAME FROM STOCK S, DEALERS D


WHERE S.DCODE=D.DCODE;

47
BIBLIOGRAPHY

48

You might also like