You are on page 1of 45

INDEX

S. NO NAME OF PRACTICAL PAGE NO SIGN OF TEACHER


1. Write a program to enter two numbers and print the arithmetic
operations like +,-,*, /, // and % as per user choice.
2. Write a program to check entered number is Armstrong or not.
3. Write a program to enter the number of terms and to print the
Fibonacci series.
4. Write a program to enter the string and display the longest word
present in the entered string.
5. Write a python function that takes a number as a parameter and
checks whether a number is prime or not.
6. Write a python function to add the first ‘n’ terms of the series:
1+1/2-1/3+1/4-1/5+………………………
7. Write a program that accepts a hyphen-separated sequence of
words as input and print the words in a hyphen-separated sequence
after storing them alphabetically.
8. Write a python function to calculate the factorial of a number (a
non-negative integer). The function accepts the number whose
factorial is to be calculated as the argument.
9. Write a program to remove all the lines that contain the character
“b” in a file and write it into another text file.
10. Write a program to read a text file and display the number of
vowels/consonants/uppercase/lowercase characters in the file.
11. Write a program to create a binary file with name and roll no. Search
for a given roll number and display the name, if not found display
appropriate message.
12. Write a program to create a binary file to store Roll no, Name and
Marks and update marks of entered Roll no.
13. Write a program to implement a stack using a list data structure.
14. Write a program to read a text file line by line and display each word
separated by #.
15. Write a program to accept string/sentences from the user till the
user enters “END”. Save the data in a text file and then display only
those sentences which begin with an uppercase alphabet.
16. Write a program to read a file ‘Story.txt’ and create another file,
storing an index of ‘Story.txt’, telling which line of the file each
words appears in. If word appears more than once, then index
should show all the line numbers containing the word.
17. Write a program to display the size of the file after removing EOL
characters, leading and trailing white spaces and blank lines.
18. Raj has been asked to display all the students who have secured less
than 40 for Remedial Classes. Write a user-defined function to
display those students who have secured less than 40 from the
binary file “Student.dat”.
19. Write a program to create CSV file and store empno, name, salary
and search any empno and display name, salary and if not found
appropriate message.
20. Write a menu driven program to implement Stack in Python using

1
List.
21. Write a program to connect with database and store record of
employee and display records.
22. Write a program to connect with database and search employee
number in table employee and display record, if empno not found
display appropriate message.
23. Write a program to connect with database and update the employee
record of entered empno.
24. Write a program to connect with database and delete the record of
entered employee number.
25. Create a student table and insert data. Implement the following SQL
commands on the student table: (a) ALTER table to add new
attributes / modify data type / drop attribute (b) UPDATE table to
modify data (c) ORDER By to display data in ascending / descending
order (d) DELETE to remove tuple(s) (e) GROUP BY and find the min,
max, sum, count and average.
26. Create a table STUDENT and write sql commands.
27. Consider the following table named “Soft drink”. Write commands
of SQL
28. Write an output for SQL queries (i) to (iii), which are based on the
table.
29. Write the output of the queries (a) to (d) based on the table, CLUB
given.
30. Write SQL commands for the following queries (i) to (iv) based on
the relations Product and Client given.

2
1. Write a program to enter two numbers and print the
arithmetic operations like +,-,*,/,// and % as per user choice.
Ans:-

3
2. Write a program to check entered number is Armstrong or
not.
Ans:-

4
3. Write a program to enter the number of terms and to
print the Fibonacci series.
Ans:-

5
4. Write a program to enter the string and display the
longest word present in the entered string.
Ans:-

6
5. Write a python function that takes a number as a
parameter and checks whether a number is prime or
not.
Ans:-

7
6. Write a python function to add the first ‘n’ terms of the
series:
1+1/2-1/3+1/4-1/5+………………………
Ans:-

8
7. Write a program that accepts a hyphen-separated
sequence of words as input and print the words in a
hyphen-separated sequence after storing them
alphabetically.
Sample Items: green-red-yellow-black-white
Expected Result: black-green-red-white-yellow

Output:-

9
8. Write a python function to calculate the factorial of a
number (a non-negative integer). The function accepts
the number whose factorial is to be calculated as the
argument.
Output:-

10
9. Write a program to remove all the lines that contain the
character “b” in a file and write it into another text file.

Output:-

11
10. Write a program to read a text file and display the
number of vowels/consonants/uppercase/lowercase
characters in the file.
Output:-

12
11. Write a program to create a binary file with name
and roll no. Search for a given roll number and display
the name, if not found display appropriate message.
Output:-

13
12. Write a program to create a binary file to store Roll
no, Name and Marks and update marks of entered Roll
no.
Output:-

14
13. Write a program to implement a stack using a list
data structure.
Output:-

15
14. Write a program to read a text file line by line and
display each word separated by #.

Output:-

16
15. Write a program to accept string/sentences from
the user till the user enters “END”. Save the data in a
text file and then display only those sentences which
begin with an uppercase alphabet.

Output:-

17
16. Write a program to read a file ‘Story.txt’ and create
another file, storing an index of ‘Story.txt’, telling which
line of the file each words appears in. If word appears
more than once, then index should show all the line
numbers containing the word.

Output:-

18
17. Write a program to display the size of the file after
removing EOL characters, leading and trailing white
spaces and blank lines.

Output:-

19
18. Raj has been asked to display all the students who
have secured less than 40 for Remedial Classes. Write a
user-defined function to display those students who
have secured less than 40 from the binary file
“Student.dat”.
Output:-

20
19. Write a program to create CSV file and store
empno, name, salary and search any empno and display
name, salary and if not found appropriate message.

Output:-

21
20. Write a menu driven program to implement Stack
in Python using List.
Output:-

22
21. Write a program to connect with database and
store record of employee and display records.

Output:-

23
22. Write a program to connect with database and
search employee number in table employee and display
record, if empno not found display appropriate
message.

Output:-

24
23. Write a program to connect with database and
update the employee record of entered empno.

Output:-

25
24. Write a program to connect with database and
delete the record of entered employee number.

Output:-

26
25. Create a student table and insert data. Implement
the following SQL commands on the student table:
(a) ALTER table to add new attributes / modify data
type / drop attribute
(b) UPDATE table to modify data
(c) ORDER By to display data in ascending / descending
order
(d) DELETE to remove tuple(s)
(e) GROUP BY and find the min, max, sum, count and
average.

(a) To add new column:

27
To modify data type:

To drop column:

28
(b) To modify data:

(c) Sort data in ascending/descending order

29
(d) To delete tuple

(e) To group records

30
26. Create a table STUDENT and write sql commands for (a) to (f)
and write the outputs for (e) and (g) on the basis of the table
STUDENT:

TABLE: STUDENT

SNO NAME STREAM FEES AGE SEX

1 ARUN COMPUTER 750.00 17 M


KUMAR

2 DIVYA JENEJA COMPUTER 750.00 18 F

3 KESHAR BIOLOGY 500.00 16 M


MEHRA

4 HARISH ENG.DR. 350.00 18 M


SINGH

5 PRACHI ECONOMICS 300.00 19 F

6 NISHA ARORA COMPUTER 750.00 15 F

7 DEEPAK ECONOMICS 300.00 16 M


KUMAR

8 SARIKA BIOLOGY 500.00 15 F


VASWANI

(a )List the name of all students who have taken stream as


COMPUTER.
(b) To count the number of female students.
(c )To display the number of students stream wise.
(d) To insert a new row in the student table :
9, “KARISHMA”, “ECONOMICS”,300,18, “F”.
(e) To display a report, listing NAME, STREAM, SEX and stipend
where stipend is 20% of the fees.

31
(f) To display all the records in stored order of name.

(a) SELECT NAME FROM STUDENT WHERE STREAM=’COMPUTER’;

(b) SELECT COUNT(SEX) FROM STUDENT WHERE SEX=’F’;

32
(c) SELECT STREAM,COUNT(STREAM) FROM STUDENT GROUP BY STREAM;

(d) INSERT INTO STUDENT VALUES(9,’KARISHMA’,’ECONOMICS’,300,18,’F’);

33
(e) ALTER TABLE STUDENT ADD STIPEND INT;
UPDATE STUDENT SET STIPPEND=0.2*FEES;

(f) SELECT * FROM STUDENT ORDER BY SNO;

34
27. Consider the following table named “Softdrink”. Write
commands of SQL for (i) to (iv).

TABLE:SOFTDRINK
DRINKCODE DNAME PRICE CALORIES

101 Lime and Lemon 20.00 120

102 Apple Drink 18.00 120

103 Nature Nectar 15.00 115

104 Green Mango 15.00 140

105 Aam Panna 20.00 135

106 Mango Juice Bahaar 12.00 150

(i) To display names and drink codes of those drinks


that have more than 120 calories.
(ii) To display drink codes, names and calories of all
drinks, in descending order of calories.
(iii) To display names and price of drinks that have price
in the range 12 to 18 (both 12 and 18 included).
(iv) Increase the price of all drinks in the given table by
10%.

OUTPUTS:-

35
(i) SELECT DNAME, DRINKCODE FROM SOFTDRINK WHERE CALORIES>120;

(ii) SELECT DRINKCODE,DNAME,CALORIES FROM SOFTDRINK ORDER BY


CALORIES DESC;

(iii) SELECT DNAME,PRICE FROM SOFTDRINK WHERE PRICE BETWEEN 12 AND


18;

36
(iv) UPDATE SOFTDRINK SET PRICE=PRICE+0.1*PRICE;

37
28. Write a output for SQL queries (i) to (iii), which are
based on the table : student given below:

Table: Student
ROLLNO NAME CLASS DOB GENDER CITY MARKS

1 Nanda X 06-06-1995 M Agra 551

2 Saurabh XII 07-05-1993 M Mumbai 462

3 Sonal XI 06-05-199 F Delhi 400


4

4 Trisla XII 08-08-1995 F Mumbai 450

5 Aman XII 08-10-1995 M Delhi 369

6 Puja XI 12-12-1994 F Dubai 250

7 Neha X 08-12-1995 F Ranchi 377

8 Raj X 12-06-1995 M Ranchi 489

(i) Select count(*), city from student group by city having


count(*)>1;
(ii) Select max(DOB), Min(DOB) from student;
(iii) Select Name, Gender from student where city=’Delhi’;
Write a SQL queries for (i) to (iv), which are based on the
table: student.
(i) To display the records from table student in
alphabetical order as per the name of the student.
(ii) To display Class, DOB and City whose marks is
between 450 and 551.
(iii) To display Name, Class and total number of students
who have secured more than 450 marks, class wise.

38
(iv) To increase marks of all students by 20 whose class is
‘XII’.
OUTPUT:-

(i) Select count(*), city from student group by city having


count(*)>1;

(ii) Select max(DOB), Min(DOB) from student;

(iii) Select Name, Gender from student where city=’Delhi’;

Write a SQL queries for (i) to (iv), which are based on the table:
student.OUTPUTS:-

(i) To display the records from table student in alphabetical


order as per the name of the student

39
(ii) To display Class, DOB and City whose marks is between
450 and 551.
SELECT CLASS,DOB,CITY FROM STUDENT WHERE MARKS BETWEEN 450 AND 551;

(iii) To display Name, Class and total number of students who


have secured more than 450 marks, class wise.
SELECT NAME,CLASS,COUNT(*) FROM STUDENT WHERE MARKS>450 GROUP BY
CLASS;

(iv) To increase marks of all students by 20 whose class is ‘XII’.


UPDATE STUDENT SET MARKS=MARKS+20 WHERE CLASS=’XII’;

40
29. Consider the table CLUB given below.
Table: CLUB
COACH_NAM DATEOFAP
COACH_ID AGE SPORTS PAY SEX
E P

1 KRKREJA 35 KARATE 27/03/1996 1000 M

2 RAVINA 34 KARATE 20/01/1998 1200 F

3 KARAN 34 SQUASH 19/02/1998 2000 M

BASKETBAL
4 TARUN 33 01/01/1998 1500 M
L

5 ZUBIN 36 SWIMMING 12/01/1998 750 M

6 KETKI 36 SWIMMING 24/02/1998 800 F

7 ANKITA 39 SQUASH 20/02/1998 2200 F

8 KUSH 37 KARATE 22/02/1998 1100 F

9 SHAILYA 41 SWIMMING 13/01/1998 900 M

BASKETBAL
10 39 19/02/1998 1700 M
L

Write the output of the queries (a) to (d) based on the table,
CLUB given above:

i) SELECT COUNT (DISTINCT SPORTS) FROM CLUB;


ii) SELECT MIN(AGE) FROM CLUB WHERE SEX = ‘F’;
iii) SELECT AVG(PAY) FROM CLUB WHERE SPORTS = ‘KARATE’;
iv) SELECT SUM(PAY) FROM CLUB WHERE DATEOFAPP >
‘31/01/1998’;
41
OUTPUT:-
(i) SELECT COUNT (DISTINCT SPORTS) FROM CLUB;

(ii) SELECT MIN(AGE) FROM CLUB WHERE SEX = ‘F’;

(iii) SELECT AVG(PAY) FROM CLUB WHERE SPORTS = ‘KARATE’;

(iv) SELECT SUM(PAY) FROM CLUB WHERE DATEOFAPP >


‘31/01/1998’;

42
30. Write SQL commands for the following queries (i) to
(iv) based on the relations Product and Client given below:
Table: Product

P_ID Product Name Manufacturer Price Discount

TP01 Talcum Powder LAK 40

FW05 Face Wash ABC 45 5

BS01 Bath Soap ABC 55

SH06 Shampoo XYZ 120 10

FW12 Face Wash XYZ 95

Table: Client

C_ID Client Name City P_ID

01 Cosmetic Shop Delhi TP01

02 Total Health Mumbai FW05

03 Live Life Delhi BS01

04 Pretty Woman Delhi SH06

05 Dreams Delhi TP01

43
i) Write SQL query to display Product Name and Price for all
products whose Price is in the range of 50 to 150.
ii) Write SQL query to display details of product whose
manufacturer is either XYZ or ABC
iii) Write SQL query to display Product Name, Manufacturer
and Price for all Products that are not given any discount.
iv) Write SQL query to display Client Name, City, and P_ID
for all clients whose city is Delhi.
OUTPUTS:-
(i) SELECT PRODUCTNAME,PRICE FROM PRODUCT WHERE PRICE BETWEEN
50 AND 150;

(ii) SELECT * FROM PRODUCT WHERE MANUFACTURER=’XYZ’ OR


MANUFACTURER=’ABC’;

44
(iii) SELECT PRODUCT_NAME,MANUFACTURER,PRICE FROM PRODUCT
WHERE DISCOUNT IS NULL;

(iv) SELECT CLIENT_NAME,CITY,P_ID FROM CLIENT WHERE CITY=’DELHI’;

45

You might also like