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

Practical Program List (4)

Uploaded by

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

Practical Program List (4)

Uploaded by

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

Practical Program List

1) Write a code where you use the wrong number of arguments for a method (say sqrt( ) or pow( )).
Use the exception handling process to catch the ValueError exception.

2) WAP to read a file’s first three lines – line by line.

3) WAP to display the size of a file after removing EOL characters, leading and trailing while spaces
and blank lines.

4) WAP to display the size of a file in bytes and the number of lines in the file.
5) Write a function ETCount( ) in Python which should read each character of a text file “poem.txt”
and then count and display the count of occurrence of alphabets E and T individually (including
small cases e and t too).

6) WAP to read a text file and display the count of lowercase and uppercase letters in the file.

7) Read a text file and display the number of vowels/consonants/uppercase/lowercase characters in


the file. Vowels/Consonants

8) WAP 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.
9) Remove all the lines that contain the character 'a' in a file and write it to another file.

10) Create a binary file with roll number, name and marks. Input a roll number, name and update the
marks. Search for a roll number and display the details, if not found display appropriate message.
11) WAP to increase the salary by Rs. 2000 of the employee having empno entered by the user from
the file emp.dat

12) WAP to read following details of sports’ performance (sport, competitions, prizes-won) of your
school and store into a csv file and display the records.
13) WAP to get item details (code, description and price) for multiple items from the user and create
a csv file by writing all the item details in one go.

14) Write a function in Python, Push(SItem) where, SItem is a dictionary containing the details of
stationary items – {Sname:price}. The function should push the names of those items in the stack
who have price greater than 75. Also display the count of elements pushed into the stack.

15) WAP to create a stack for storing only odd numbers out of all the numbers entered by the user.
Display the content of the stack along with the largest odd number in the stack.
16) WAP to check whether the given string is palindrome or not, using deque.

17) WAP that takes as input a list having a mix of 10 negative and positive numbers and a key value.
Apply linear search to find whether the key is present in the list or not. If the key is present it
should display the position of the key in the list otherwise it should print an appropriate message.
18) During admission in a course, the names of the students are inserted in ascending order. Thus,
performing the sorting operation at the time of inserting elements in a list, write a program using a
user defined function that is invoked every time a name is entered and stores the name in
ascending order of names in the list.

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

20) WAP that defines and calls the following user defined functions:
i) ADD( ) : To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists
of a list with field elements as empid, name, and mobile to store employee-id, employee name and
employee salary respectively.
ii) COUNTR( ): To count the number of records present in the CSV file named ‘record.csv’
Database Management – SQL Queries
1) Suppose your school management has decided to conduct cricket matches between students of Class XI and
Class XII. Students of each class are asked to join any one of the four teams – Team Titan, Team Rockers,
Team Magnet and Team Hurricane. During summer vacations, various matches will be conducted between
these teams. Help your sports teacher to do the following:
a) Create a database “Sports”.
b) Create a table “TEAM” with following considerations:
i) It should have a column TeamID for storing an integer value 1 to 9, which refers to unique
identification of a team.
ii) Each TeamID should have its associated name (TeamName), which should be a string of length not less
than 10 characters.
c) Using table level constraint, make TeamID as the primary key.
d) Show the structure of the table TEAM using a SQL statement.
e) As per the preferences of the students four teams were formed as given below. Insert these four rows in
TEAM table:
Row1: (1, Team Titan)
Row2: (2, Team Rockers)
Row3: (3, Team Magnet)
Row4: (4, Team Hurricane)
f) Show the contents of the table TEAM using a DML statement.
g) Now create another table MATCH_DETAILS and insert data as shown below. Choose appropriate data
types and constraints for each attribute.
MatchID MatchDate FirstTeamID SecondTeamID FirstTeamScore SecondTeamScore
M1 2018-07-17 1 2 90 86
M2 2018-07-18 3 4 45 48
M3 2018-07-19 1 3 78 56
M4 2018-07-19 2 4 56 67
M5 2018-07-18 1 4 32 87
M6 2018-07-17 2 3 67 51
2) Consider the following table named “Product”, showing details of products being sold in a grocery shop.
PCode PName UPrice Manufacturer
P01 Washing Powder 120 Surf
P02 Toothpaste 54 Colgate
P03 Soap 25 Lux
P04 Toothpaste 65 Pepsodent
P05 Soap 38 Dove
P06 Shampoo 245 Dove
Write SQL queries for the following:
a) Create the table Product with appropriate data types and constraints.
b) Identify the primary key in Product.
c) List the Product Code, Product name and Price in descending order of their product name. If PName is
the same, then display the data in ascending order of Price.
d) Add a new column Discount to the table Product.
e) Calculate the value of the discount in the table Product as 10% of the UPrice for all those products
discount will be 0.
f) Increase the price by 12% for all the products manufactured by Dove.
g) Display the total number of products manufactured by each manufacturer.

3) Consider the following MOVIE table and write the SQL queries based on it.
MovieID MovieName Category ReleaseDate ProductionCost BusinessCost
001 Hindi_Movie Musical 2018-04-23 124500 130000
002 Tamil_Movie Action 2016-05-17 112000 118000
003 English_Movie Horror 2017-08-06 245000 360000
004 Bengali_Movie Adventure 2017-01-04 72000 100000
005 Telugu_Movie Action - 100000 -
006 Punjabi_Movie Comedy - 30500 -
a) Display all the information from the Movie table.
b) List business done by the movies showing only MovieID, MovieName and Total_Earning.
Total_Earning to be calculated as the sum of ProductionCost and BusinessCost.
c) List the different categories of movies.
d) Find the net profit of each movie showing its MovieID, MovieName and NetProfit. Net Profit is to
be calculated as the difference between BusinessCost and ProductionCost.
e) List MovieID, MovieName and Cost for all movies with ProductionCost greater than10000 and
less than 100000.
f) List details of all movies which fall in the category of comedy or action.
g) List details of all movies which have not been released yet.
4) Create a database CARSHOWROOM, has the following four relations:
i) INVENTORY(CarID, CarName, Price, Model, YearOfManufature, FuelType),
ii) CUSTOMER(CustomerID, Name, Address, PhNumber, Email),
iii) SALE(InvoiceNumber, CarID, CustomerID, SaleDate, ModeOfPayment, Sales person’s employee
ID(EmpID), and selling price of the car sold(SalePrice),
iv) EMPLOYEE(EmpID, Name, DOB, DateOfJoining, Designation and Salary of each employee in the
showroom.
a) Calculate GST as 12% of the CarPrice and display the result after rounding it off to one decimal
place.
b) Add a new column FinalPrice to the table inventory which will have the value as sum of Price and
12%of the GST.
c) Calculate and display the amount to be paid each month (in multiples of 1000) which is to be
calculated after dividing the FinalPrice of the car into 10 installments.
d) After dividing the amount into EMIs, find out the remaining amount to be paid immediately, by
performing modular division

5) Create a database OFFICE that has many related tables like EMPLOYEE, DEPARTMENT. Every
Employee in the database is assigned to a DEPARTMENT and his/her Department number(DeptID) is
stored as a foreign key.
a) Write a query to display the distinct salaries of the employees working in the department number
D01. (using ‘DISTINCT’)
b) Write a query to display the details of those employees of D04 department who earn more than
5000.
c) Write a query to display records of all the employees except ‘aaa’
d) Write a query to display the name and department number of all those employees who are earning
salary between 20000 and 50000(both values inclusive)

6) Create the STUDENT-PROJECT database to store the data in the form of following Relations:
STUDENT(RollNo, Name, Class, Section, Registration_ID)
PROJECT(ProjectNo, PName, SubmissionDate)
PROJECT_ASSIGNED(Registration_ID, ProjectNo)
Values to PName should be – (Airline Database, Library Database, Employee Database, Student
Database, Inventory Database, Railway Database).
Registration_ID should be under the categories – IP and CS.
7) Create a database and tables and execute the SQL queries (i) to (iv) based on the relations Teacher and
Placement given below:
Table: TECH_COURSE
CID CNAME FEES STARTDATE TID
C201 Animation and VFX 12000 2022-07-02 101
C202 CADD 15000 2021-11-15 NULL
C203 DCA 10000 2020-10-01 102
C204 DDTP 9000 2021-09-15 104
C205 Mobile Application Development 18000 2022-11-01 101
C206 Digital marketing 16000 2022-07-25 103
i) Write a query to display the distinct TID from the above relation.
ii) Display TID, COUNT(*), Min(FEES) grouping by TID having COUNT(TID)>1
iii) Display CNAME from the above relation where the FEES > 15000 ordering by CNAME
iv) Display AVG(FEES) where the FEES between 15000 and 17000.

8) Consider the following table named “Product”, showing details of products being sold in a grocery shop.
PCode PName UPrice Manufacturer
P01 Washing 120 Surf
Powder
P02 Toothpaste 54 Colgate
P03 Soap 25 Lux
P04 Toothpaste 65 Pepsodent
P05 Soap 38 Dove
P06 Shampoo 245 Dove
Write SQL commands and execute it:
i) Create the table Product with appropriate data types and constraints.
ii) Identify the primary key in Product.
iii) List the Product Code, Product name and Price in descending order of their product name. If
PName is the same, then display the data in ascending order of Price.
iv) Add a new column Discount to the table Product.
v) Calculate the value of the discount in the table Product as 10% of the UPrice for all those products
discount will be 0.
vi) Increase the price by 12% for all the products manufactured by Dove.
vii) Display the total number of products manufactured by each manufacturer.
9) Table: Doctor
D_id Dname Gender Age Mobile Salary
D123 Swati Garg F 35 987321456 85000
D234 Anirudh M 40 987456321 91000
D456 Rupinde Kaur F 32 963258741 95850
D656 Shailender M 42 910236547 98750
Gupta
D234 Yashika Lamba F 39 989955222 75300
D334 Deepak M 45 998877445 85400

Table: D_Dept
D_id Department Charges OPD_Days
D123 Gynecology 700 MWF
D234 Cardiology 850 MWF
D456 Gynecology 700 TTS
D656 Cardiology 850 MWS
D234 ENT 900 TTS
D334 Neurology 950 TTS
Write SQL queries and execute the same on the basis of above tables Doctor and D_Dept.
a) Display total salary of the doctors according to the department wise.
b) Increase the charges of Neurology department to 10%.
c) Show the details of the male doctors whose age is between 40 to 50 and having OPD_Days on
MWF.
d) Show the details of the name, department and age according to their salary in highest to lowest
order.

10) Create a table RESULT with a set of records to maintain the marks secured by students in Sem1,
Sem2, Sem3 and their division and enter the data of 7 students in the table.
Roll_No Sname Sem1 Sem2 Sem3 Division
101 Karan 366 410 402 I
102 Naman 300 350 325 I
103 Isha 400 410 415 I
104 Renu 350 357 415 I
105 Arpit 100 75 178 IV
106 Sabina 100 205 217 II
107 Neelam 470 450 471 I
Based on the data given above write the SQL queries and execute the following:
a) Identify the most appropriate column to assign as a Primary Key.
b) Insert the following record into the table:
i) RollNo-108, Name-Aaditya, Sem1- 470, Sem2 – 444, sem3 – 475, Div – I.
ii) Increase the Sem2 marks of the students by 3% whose name begins with ‘N’
c) Delete the record of students securing IV division.
d) Add a column REMARKS in the table with datatype as varchar with 50 characters
11) Consider the table CLUB given below: Write and execute the statements that follow using the
appropriate SQL queries.
CID CNAME AGE GENDER SPORTS PAY DOAPP
5246 Amrita 35 Female Chess 900 2006-03-
27
4687 Harish 37 Male Cricket 1300 2004-04-
15
1245 Vidhya 23 Female VolleyBall 1000 2007-06-
18
1622 Arun 28 Male Karate 1000 2007-09-
05
1256 Anu 36 Female Chess 1100 2003-08-
15
1720 Netra 33 Female Karate 1250 2004-04-
10
2321 Vijay 35 Male Cricket 1050 2005-04-
30
i) Display the COUNT(DISTINCT SPORTS) from the above relation.
ii) Display CNAME, SPORTS from the above relation where the DOAPP < “2006-04-30 and CNAME
ends with ‘a’.
iii) Display CNAME, AGE, PAY from the above table where the GENDER = “Male” and the PAY between
1000 and 1200.

12) Consider the table Personal given below:


Table: Personal
P_ID Name Desig Salary Allowance
P01 Rohit Manager 89000 4800
P02 Kashish Clerk NULL 1600
P03 Mahesh Supervisor 48000 NULL
P04 Sathish Clerk 31000 1900
P05 Priya Supervisor NULL 2100

Write the SQL commands and execute the following:


a) Increase the salary by 5% of personals whose allowance is known.
b) Display Name and Total Salary (sum of Salary and Allowance) of all personals. The column
heading ‘Total Salary’ should also be displayed.
c) Delete the record of Supervisors who have salary greater than 25000
13) Consider the tables PRODUCT and BRAND given below:
Table: PRODUCT Table: BRAND
PCode Pname Uprice Rating BID BID Bname
P01 Shampoo 120 6 M03 M02 Dant
P02 Toothpaste 54 8 M02 Kanti
P03 Soap 25 7 M03 M03 Medimix
P04 Toothpaste 65 4 M04 M04 Pepsodent
P05 Soap 38 5 M05 M05 Dove
P06 Shampoo 245 6 M05

Write the SQL commands and execute the following:


i) Display product name and brand name from the tables PRODUCT and BRAND.
ii) Display the structure of the table PRODUCT.
iii) Display the average rating of Medimix and Dove brands.
iv) Display the name, price, and rating of products in descending order of rating.

14) Consider the following tables STUDENT and STREAM:


Table: STUDENT Table: STREAM
Admno Name Class Sec Streamid
Streamid Sname
1101 Naveen XII A 10
10 Medical
1102 Chetna XII A 10
20 NonMedical
1103 Ishaan XI C 30
30 Commerce
1104 Sathish XII B 20
40 Humanities
1105 Tejas XI A 10
1106 Zoya XI B 20
1107 Swati XII D 40

Write the SQL commands and execute the following:


a) Display the admission number and name of all the students who are in class X.
b) Display unique streamid from the table student.
c) To count number of students who are in class XII and streamid is 10.
d) Add a new stream (50, Vocational).
15) Consider the relation given below:
Table: Pharma BD
RxID DrugID DrugName Price PharmacyName PharmacyLocaiton
R1000 5476 Amlodipine 100.00 RxPharmacy Pitampura, Delhi
R1001 2345 Paracetamol 15.00 Raj Medicos Bahadurgarh, Haryana
R1002 1235 Nebistar 60.00 MyChemist Rajouri Garden, Delhi
R1003 6512 VitaPlus 150.00 MyChemist Gurgaon, Haryana
R1004 5631 Levocitrezine 110.00 RxPharmacy South Extension, Delhi

Write the SQL commands and execute the following:


a) To count the total number of records.
b) To display the maximum and average price of the medicines.
c) To display the count the number of medicines which ends with ‘ine’

16) A relation Vehicle is given below:


Relation: Vehicle
Vno Type Company Price Qty
AW125 Wagon Maruti 250000 25
J0083 Jeep Mahindra 4000000 15
S9090 SUV Mitsubishi 2500000 18
M0982 Mini Van Datsun 1500000 26
W9760 SUV Maruti 2500000 18
R2409 Mini Van Mahindra 350000 15
Write the SQL commands and execute the following:
a) Count the type of vehicles manufactured by each company.
b) Display the total price (Price*Qty) of all the types of vehicles.
c) To display Vno, Type, and Company from the table vehicle in descending order of Vno.
17) Table: Doctor
D_id Dname Gender Age Mobile Salary
D123 Swati Garg F 35 987321456 85000
D234 Anirudh M 40 987456321 91000
D456 Rupinde Kaur F 32 963258741 95850
D656 Shailender M 42 910236547 98750
Gupta
D234 Yashika Lamba F 39 989955222 75300
D334 Deepak M 45 998877445 85400

Table: D_Dept
D_id Department Charges OPD_Days
D123 Gynecology 700 MWF
D234 Cardiology 850 MWF
D456 Gynecology 700 TTS
D656 Cardiology 850 MWS
D234 ENT 900 TTS
D334 Neurology 950 TTS
Write SQL queries and execute the same on the basis of above tables Doctor and D_Dept.
a) Display total salary of the doctors according to the department wise.
b) Increase the charges of Neurology department to 10%.
c) Show the details of the male doctors whose age is between 40 to 50 and having OPD_Days on MWF.
d) Show the details of the name, department and age according to their salary in highest to lowest order.

SQL Connectivity
1) Note the following to establish connectivity between Python and MYSQL:
- Username is root
- Password is _____
- The table exists in a MYSQL database named school.
- Insert the given details in the table student (RollNo, Name, Class, Marks) are to be
accepted from the user.PgNo.642, PrNo-12
2) WAP that displays first three rows fetched from student table of MySQL database.PgNo.632,PrNo-16.1
3) WAP to read the following record (RollNo, Name, Class, Marks) from the table student and displays only
those records who have scored the marks greater than 75.PgNo.643,PrNo-13.
4) Write a Python database connectivity script that deletes records from category table of database items that
have name = ‘Stockable’. PgNo.642,PrNo-11

You might also like