0% found this document useful (0 votes)
39 views26 pages

Document 7

Uploaded by

Allen Sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views26 pages

Document 7

Uploaded by

Allen Sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

PROGRAM 1

1. Python program that accepts a number as argument into a function


perfect () and checks if it is a Perfect number or not. Print the result

SOURCE CODE

OUTPUT
PROGRAM 2
2. Python user defined function palindrome () that accepts a number as an
argument and return 1 if the number is palindrome else return -1. Print the
result.

SOURCE CODE

OUTPUT
PROGRAM 3
3. Python user defined function to find the count of duplicate elements in a
tuple given by the user, along with the element and display it.

SOURCE CODE

OUTPUT
PROGRAM 4
4. Python user defined function that accepts a list as argument and display
all the numbers in the list with start and end with the same digit.

SOURCE CODE

OUTPUT
PROGRAM 5
5. Python program that accepts n integers to a list and returns all the odd
numbers divisible by 3. Display such numbers.

SOURCE CODE

OUTPUT
PROGRAM 6
6. Python program that generates n integers between 5 and 55 randomly
and stores into a tuple. Send this tuple as argument to a function task (),
which will return all the numbers in the tuple divisible by 5 as a tuple. Print
the resultant tup

SOURCE CODE

OUTPUT
PROGRAM 7
7. Python program to create and read a text file ‘novel.txt’ with n strings and
display the count of vowels, consonants, digits, lower case, upper case and
special characters.

SOURCE CODE

OUTPUT
PROGRAM 8
8. Python program to read a text file ‘info.txt’ and display the shortest word
in the file. Also display the words starting with uppercase consonant in the
file.

SOURCE CODE

OUTPUT
PROGRAM 9
9. Python program to copy the lines that starts with ‘Please’ from a text file
into another text file ‘request.txt’. The name of the text file should be
entered by the user at run time. Display the contents of ‘request.txt’.

SOURCE CODE

OUTPUT
PROGRAM 10
10. Python program to create a binary file ‘food.dat’ that has information
about food items, such that the data comes from a dictionary created by the
user. The key of the dictionary is the name of the food item and value is a
tuple with 3 elements pertaining to three ingredients to make that item.
Read this binary file and display its contents.

SOURCE CODE

OUTPUT
PROGRAM 11

11.Creating a python program to create and update/modify records in binary


file ‘cosmetics.dat’ having the following structure {name: [brand, price]}
(i) Add n records to the file
(ii) Modify the price if the name of a product is entered Display the resultant
file.

SOURCE CODE

OUTPUT
PROGRAM 12
12. Python program to create a binary file ‘yathri.dat’ that has information
about n cars in the format [[car_reg_no, owner_name, company, colour],…]
(nested list). Read this file and display information of the car where the
owner_name is given by the user.

SOURCE CODE

OUTPUT
PROGRAM 13

13. Python program to create a binary file ‘survey.dat’ that has information
about n house owners in the format [(house_no, name_owner, phone,
no_of_mem),..]. Read this file and delete the information of the house_no
given by the user. Display the file contents before and after deletion.

SOURCE CODE

OUTPUT
PROGRAM 14

14. Creating a Python program that defines and invokes the following user
defined functions: (i) add_item() : Takes the details of the items in a
warehouse and adds them to a CSV FILE ‘items.csv’. Each record consists of
a list with fields item_no, itname, price. (ii) search() : Takes price as
argument and counts and displays number of items where price is less than
the price given by the user.

SOURCE CODE

OUTPUT
PROGRAM 15
15. Python program to implement stack operations (Using List). The list contains the
following record of an individual – [phone_no, name, address] The program should
have the following user defined functions to perform given operations of the stack
named ‘tele_dir’ (i) push_indiv() – To push the individual’s details into the list (ii)
pop_ indiv () – To pop the details of one individual from the stack and display them.
Also display “underflow” when there are no individuals in the stack. (iii) display() –
To display all the details of the individuals in the stack.

SOURCE CODE
OUTPUT

PROGRAM 16
16. Python program to implement stack operations (Using Dictionary). The
dictionary contains details of pilots - {flight_no: destination} The program should
have the following user defined functions to perform given operations of the stack
named ‘pilot_info’ (i) push_info () – To push the destination given by the user of
flight_no = 1001 into the stack. (ii) pop_info() – To pop the details of one flight from
the stack and display them. Also display “Underflow” when there are no records in
the stack. (iii) display() – To display all the details of the flights in the stack.

SOURCE CODE
OUTPUT

PROGRAM 17
17. Write a Python program to create a database – bank. Use this database and create a
table with the following details:
User Name – root , Password – toch , Name of the table - account
• The attributes of account are as follows: ac_no – numeric which is a Primary key, name –
character of size 20 which should not be null, type – char(1) (can be ‘s’ for savings, ‘c’ for
current account) amount – numeric by default the value should be set as 0
(a) Display the message “table created” after creating the table.
(b) Add 4 records to the table.

SOURCE CODE

OUTPUT

PROGRAM 18
18. Write a Python program to do the following: Use this database bank and
(a) display all data of records two to three from the table account. (b) display
the ac_no, name, amount of all items whose name starts with ‘A’.

SOURCE CODE
OUTPUT

PROGRAM 19

19. Write a Python program to do the following using the table account of
database bank: (a) Deposit user given amount, if the ac_no and new amount
is entered by the user.
(b) Display all the records in descending order of amount.
SOURCE CODE
OUTPUT
PROGRAM 20
20. Write a Python program to delete the record whose ac_no is 504 and
display the remaining records in the table account of bank database. Also,
display the total number of records in the table.

SOURCE CODE

OUTPUT
PROGRAM 21

21. Write SQL commands and their outputs based on the given tables of
Database ‘Sport’:

1. Create the Table GAME with the following specifica􀆟ons :


SCODE char(4) set as PRIMARY KEY,
SNAME varchar(15) set as NOT NULL AND UNIQUE,
VENUE varchar(10)
NO_OF_PARTI integer (maximum 20)
PRIZE integer default is 5000
SCH_DATE date

mysql> Create table GAME


-> (Scode char(4) primary key,
-> Sname varchar(15) not null unique,
-> Venue varchar(10),
-> No_of_parti int check No_of_parti < 20,
-> Prize int default 5000,
-> Sch_Date date);
Query OK, 0 rows affected (0.01 sec)

2. Add a record ‘C005’, ‘NISHAD’, ‘S003’ to the table COACH.

mysql> Insert into COACH values('C005','NISHAD','S003');


Query OK, 1 row affected (0.00 sec)

3. Display the structure of the table GAME.

mysql> desc GAME;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| Scode | char(4) | NO | PRI | NULL | |
| Sname | varchar(15) | NO | UNI | NULL | |
| Venue | varchar(10) | YES | | NULL | |
| No_of_parti | int(11) | YES | | NULL | |
| Prize | int(11) | YES | | 5000 | |
| Sch_Date | date | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)

4. Display the number of VENUEs without redundancy.

mysql> Select count(distinct venue) from GAME;


+-----------------------+
| count(distinct venue) |
+-----------------------+
| 3 |
+-----------------------+
1 row in set (0.01 sec)

5. Display the SNAME with NO_OF_PARTI > 10.

mysql> Select Sname from GAME


-> where No_of_parti > 10;
+-----------+
| Sname |
+-----------+
| RELAY |
| SHOT PUT |
| LONG JUMP |
+-----------+
3 rows in set (0.01 sec)

6. Display the SNAME with SCH_DATE after ‘September, 2024’ .

mysql> Select Sname from GAME


-> where Sch_Date > '2024-09-30';
+-----------+
| Sname |
+-----------+
| SHOT PUT |
| LONG JUMP |
+-----------+
2 rows in set (0.00 sec)

7. Display the SNAME with the letter ‘u’ in it.

mysql> Select Sname from GAME


-> where Sname like '%u%';
+-----------+
| Sname |
+-----------+
| HIGH JUMP |
| LONG JUMP |
| SHOT PUT |
+-----------+
3 rows in set (0.00 sec)

8. Display the SNAME in descending order of PRIZE.

mysql> Select Sname from GAME


-> order by Prize desc;
+-----------+
| Sname |
+-----------+
| HIGH JUMP |
| RELAY |
| LONG JUMP |
| SHOT PUT |
+-----------+
4 rows in set (0.00 sec)

9. Display the minimum & maximum PRIZE of the Games.

mysql> select min(Prize),max(Prize) from GAME;


+------------+------------+
| min(Prize) | max(Prize) |
+------------+------------+
| 8000 | 12000 |
+------------+------------+
1 row in set (0.00 sec)

10. Display the CNAME of SCODE ‘S001’.

mysql> Select Cname from COACH


-> where Scode = 'S001';
+-------+
| cname |
+-------+
| ARUN |
| ALI |
+-------+
2 rows in set (0.00 sec)

11. Count the total number of games under each VENUE.


mysql> select Venue,count(*) from GAME
-> group by Venue;
+---------+----------+
| Venue | count(*) |
+---------+----------+
| ANNEX 1 | 2 |
| ANNEX 2 | 1 |
| ANNEX 3 | 1 |
+---------+----------+
3 rows in set (0.00 sec)

12. Display the SNAME and the corresponding CNAME.

mysql> select Sname, Cname from GAME, COACH


-> where GAME.Scode = COACH.Scode;
+-----------+---------+
| Sname | Cname |
+-----------+---------+
| HIGH JUMP | ARUN |
| LONG JUMP | PRANAV |
| SHOT PUT | AHMED |
| RELAY | SANDEEP |
| HIGH JUMP | ALI |
| SHOT PUT | NISHAD |
+-----------+---------+
6 rows in set (0.01 sec)

13. Change the VENUE of ‘S002’ to ‘ANNEX 1’.

mysql> update GAME


-> set Venue = 'ANNEX 1'
-> where Scode = 'S002';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

14. Display the GAMES whose PRIZE > 10000.

mysql> Select Sname from GAME


-> where Prize > 10000;
+-----------+
| Sname |
+-----------+
| HIGH JUMP |
+-----------+
1 row in set (0.00 sec)
15. Add a column ‘PHNO’ of data type varchar(15) to the table
COACH.

mysql> Alter table COACH


-> Add PHNO varchar(15);
Query OK, 6 rows affected (0.02 sec)
Records: 6 Duplicates: 0 Warnings: 0

16. Delete the data from GAME table where SNAME is ‘SHOT PUT’.

mysql> Delete from GAME


-> Where Sname = "SHOT PUT";
Query OK, 1 row affected (0.01 sec)

17. Set the Column CCODE in the table COACH as Primary Key.

mysql> Alter table COACH


-> ADD Primary key (Ccode);
Query OK, 6 rows affected (0.02 sec)
Records: 6 Duplicates: 0 Warnings: 0

18. Make SCODE as the foreign key of the table COACH with
reference to GAME table.

mysql> Alter table COACH


-> Add FOREIGN KEY (Scode) references GAME(Scode);
Query OK, 6 rows affected (0.03 sec)
Records: 6 Duplicates: 0 Warnings: 0

19. Delete the table COACH.

mysql> Drop table COACH;


Query OK, 0 rows affected (0.01 sec)

20. Delete the database.

mysql> Drop database Sports;


Query OK, 1 row affected (0.05 sec)

You might also like