Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Delhi Public School Bangalore East

Subject: Computer Science(2019-20)


Practical List- Python for Grade XII.
1.Create a module MassConversion.py that stores function for mass conversion ie

(i) kgtotonne() to convert kg to tonnes (ii) tonnetokg() to convert tonne to kg


(iii)kgtopound() to convert kg to pound (iv)poundto kg() to convert pound to kg
Import the module and call the functions as desired by the user.
2.Write a python program that reads characters from the keyboard one by one. All lower case
characters gets stored in the file LOWER, all upper case characters get stored in the file UPPER and
all other characters get stored in the file OTHERS.
3. Write a recursive function in Python to find:

• Factorial of a number ‘n’.


• Fibonacci Series till ‘n’ terms.
• ab where a,b are parameters.

4. Using the matplotlib library of Python, plot the line graph for the following:

(i) to calculate the value of y= sin(x) using its Taylor series expansion up to n terms.

(ii) to plot a graph for the function y = x2

5.(i)Write a Python program to create a pie chart of gold medal achievements of five most
successful countries in 2016 Summer Olympics. Sample data:

countries=[ United States, Great Britain ,China ,Russia, Germany]


gold_medals=[46,27,26,19,17]
(ii) Write a Python program to display a bar chart of the popularity of programming Languages.

Use different color for each bar. Sample data:


Programming languages=[Java, Python, PHP, JavaScript, C#, C++]
Popularity=[ 22.2, 17.6, 8.8, 8, 7.7, 6.7]

6. Write a menu driven program in Python to perform basic list operations

• Traversal in a list
• Insertion in a sorted list
• Deletion of an element from a list

1
7. Write a menu driven program to perform Searching Techniques in a list using

• Linear Search
• Binary Search

8. Write a menu driven program to perform Sorting a list using

• Bubble Sort
• Insertion Sort

9. Write a program using lists in python to:

• Find the sum of two matrices


• Find the difference of two matrices
• Product of two matrices
• Exit

10. Write a program to implement Stack Operations as a list

• Push
• Pop
• Peek
• Display Stack
• Exit

11. Write a program to implement Queue Operations as a list.

• Enqueue
• Dequeue
• Display Queue
• Exit

12. Write a Program in Python to count and display the number of lines not starting with alphabet 'A'
present in a text file "STORY.TXT”. Example: If the file "STORY.TXT" contains the following lines,

The rose is red.


A girl is playing there.
There is a playground.
An aero plane is in the sky.
Numbers are not allowed in the password.
The function should display the output as 3.

13. Write a menu driven program to:

• Create a text file


• Count number of vowels, digits and words
• Create another file using the original which will contain the text after
replacing all the blanks spaces with #.
2
14.Write a Python program using NumPy :

(i) compute the determinant of a square array using

(ii) to compute sum of all elements, sum of each column and sum of each row.

* 15. Write a Django based web application and write the data to a csv file.

* 16. Write a program to connect Python with MySQL using database connectivity and perform the
following operations on data in database: Fetch, Update and delete the data.
A .CREATE A TABLE

import mysql.connector
demodb = mysql.connector.connect(host="localhost", user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("CREATE TABLE STUDENT (admn_no int primary key,
sname varchar(30), gender char(1), DOB date, stream varchar(15), marks float(4,2))")

B. INSERT THE DATA

import mysql.connector
demodb = mysql.connector.connect(host="localhost", user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("insert into student values (%s, %s, %s, %s, %s, %s)",
(1245, 'Arush', 'M', '2003-10-04', 'science', 67.34))
demodb.commit( )

C. FETCH THE DATA

import mysql.connector
demodb = mysql.connector.connect(host="localhost", user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("select * from student")
for i in democursor:
print(i)

D. UPDATE THE RECORD

import mysql.connector
demodb = mysql.connector.connect(host="localhost", user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("update student set marks=55.68 where admn_no=1356")
demodb.commit( )
3
E. DELETE THE DATA
import mysql.connector
demodb = mysql.connector.connect(host="localhost", user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("delete from student where admn_no=1356")
demodb.commit( )

MySQL Practical List

1.Write the SQL commands for the following on the basis of SCHOOL BUS relation given below:

Rt no Area_covered Capacity No of Distance Tranporter Charges


stud
1 Vasant Kunj 100 120 10 Shivam Travels 100000
2 Hauz Khas 80 80 10 Anand Travels 85000
3 Pitampura 60 55 30 Anand Travels 60000
4 Rohini 100 90 35 Anand Travels 100000
5 Yamuna Vihar 50 60 20 Bhalla Co 55000
6 Krishna Nagar 70 80 30 Yadav Co 80000
7 Vasundhra 100 110 20 Yadav Co 100000
8 Paschin Vihar 40 40 20 Speed Travels 55000
9 Saket 120 120 10 Speed Travels 100000
10 Janak Puri 100 100 20 Kisan Tours 95000

i. To show all records students more than the capacity in order of RTNO
ii. To show area covered for buses covering more than 20Km,but charges less than 80000
iii. To show transporter wise total no of students traveling
iv. To show RTNO, area_covered and average cost per student for all routes
v. Add a new record with following data: (11,”mohit bagh”,35,32,10,”Kiran Tours” ,35000)

2.Write SQL commands for the following on the basis of table Hospital given below.

No Name Age Department Dateofadm Charges Sex

1 Sandeep 65 Surgery 23/02/98 300 M


2 Ravina 24 Orthopedic 20/01/98 200 F
3 Karan 45 Orthopedic 19/02/98 200 M
4 Tarun 12 Surgery 01/01/98 300 M
5 Zubin 36 ENT 12/01/98 250 M
6 Ketaki 16 ENT 24/02/98 300 F
7 Leena 29 Cardiology 20/02/98 800 F
8 Zareen 45 Gynecology 22/02/98 300 M
9 Kush 19 Cardiology 13/01/98 800 F

4
10 Shailya 31 Nuclear Medicine 19/02/98 400 M

1.To show all information about the patients of cardiology department.


2.To list the names of female patients who are in orthopedic department.
3.To list the names of all patients with the date of admission in ascending order.
4.To display patient’s Name, Charges ,AGE for only male patients only.
5.To count the number of patients with age greater than 30.
3.Write SQL commands for the following on the basis of Bank relation given below:
Bank
Acc_No Cname Bname Amount Transactions Dateofopen
1 Karan Bank Of Boroda 15000 10 12/01/98
2 Puneet State Bank 25000 09 1/2/97
3 Anirban Oriental Bank 17000 05 15/7/99
4 Yatin Standard Charted 38000 11 10/02/99
5 Sunny State Bank 47000 15 06/02/98
6 Jayant Uco Bank 34000 07 10/08/98
7 Nikhil Bank Of Boroda 56000 12 01/01/99
8 Tarun Oriental Bank 22000 08 04/04/99
9 Jisha Uco Bank 34500 11 05/01/98
i. Display data for all customers whose transactions are between 8 and 11.
ii. Display data for all sorted by their dateofopen in descending order.
iii. To count number of customers with amount<30000.
iv. List the minimum and maximum amount from the bank.
v. To list Cname , Bname ,amount for all the clients whose amount is <20000.

4.Write SQL commands for the following on the basis of the tables given below: WORKER

Ecode Name Desig PLevel DOJ DOB


11 Radhe Shyam Supervisior P001 13-Sept-2004 23-Aug-1981
12 Chander Nath Operator P003 22-Feb-2010 12-Jul-1987
13 Fizza Operator P003 14-Jun-2009 14-Oct-1983
15 Ammen Ahmed Mechanic P002 21-Aug-2006 13-Mar-1984
18 Sanya Clerk P002 19-Dec-2005 09-Jun-1983

Paylevel
Plevel Pay Allowance
P001 26000 12000
P002 22000 10000
P003 12000 6000

1. To display the details of all workers in descending order of DOB.


2. To display Name and Desig of those workers whose PLevel is either P001 or P002.
3. To display the content of all the worker table whose DOB is in between 19-Jan-1984 and
18-Jan- 1987.
4. To display the Name and Allowance of all employees whose PLevel is P003.
5. 5.To increase the Pay of all P001 employees by 3000.

5.Given the following Lab table, write SQL commands for the following statements.

5
No ItemName CostPerItem Quantity DateOfPurchase Warranty Operational
1. Computer 60000 9 21/5/96 2 7
2. Printer 15000 3 21/5/97 4 2
3. Scanner 18000 1 29/8/98 3 1
4. Camera 21000 2 13/10/96 1 1
5. Switch 8000 1 31/10/99 2 1
6. UPS 5000 5 21/5/96 1 4
7. Plotter 25000 2 11/1/2000 2 5

1. To select the ItemName purchased after 31/10/97.


2. To display all the ItemName whose name starts with “C”.
3. To list the ItemName in ascending order of the date of purchase where quantity is
more than 3.
4. To count the number of items whose cost is more than 10000.
5. Display the most expensive item purchased in 1996.

6.Write SQL Queries for the following EMPLOYEE and SALGRADE tables.

EMPLOYEE
ECODE NAME DESIG SGRADE DOJ DOB
101 Abdul Executive S03 23-Mar-2003 13-Jan-1980
102 Ravi Head – IT S02 12-Feb-2010 22-Jul-1987
103 John Receptionist S03 24-Jun-2009 24-Feb-1983
105 Nazar GM S02 11-Aug-2006 03-Mar-1984
106 Priyam CEO S01 29-Dec-2004 19-Jan-1982

SALGRADE

SGRADE SALARY HRA


S01 56000 18000
S02 32000 12000
S03 24000 8000

a. To display the details of all employees in descending order of DOJ.


b. To display NAME and DESIG of those Employees, whose SGRADE is either S02 or S03.
c. To display the content of all the employees table, whose DOJ is in between 09-
Feb-2006’ and ’08- Aug-2009’.
d. To add a new row with the following :19. ‘Harish Roy’, ‘Manager’, ‘So2’, ’09-Sep-2007’,’21-
Apr-1983’
e. To add a new column BONUS to the table SALGRADE which is 25% of the SALARY.

7.Write SQL commands for the following on the basis of the relations Stationery and Consumer given below:

6
Stationery Consumer
S_ID StationeryName Company Price C-ID ConsumerName Address S_ID
DP01 Dot Pen ABC 10 01 Good Learner Delhi PL01
PL02 Pencil XYZ 6 06 Write Well Mumbai GP02
ER05 Eraser XYZ 7 12 Topper Delhi DP01
PL01 Pencil CAM 5 15 Write & Draw Delhi PL02
GP02 Gel Pen ABC 15 16 Motivation Bangalore PL01

1. To display details of those Consumers whose Address is Delhi.


2. To display the details of Stationery whose Price is in the range of 8 to 15(both included).
3. To display the ConsumerName ,Address from table Consumer and Company and Price
from Table Stationery ,with their corresponding matching S_ID.
4. To increase the Price of all Stationery by 2.
5. To display the maximum & minimum Price of each company.

8.Write SQL commands for the following based on the tables Employee and Salary given below:
Employee Salary
Eid Name Deptid Qualification Sex Eid Basic D.A HRA Bonus
1 Deepali 101 MCA F 1 6000 2000 2300 200
2 Rajat 101 BCA M 2 2000 300 300 30
3 Hari 102 B.A M 3 1000 300 300 40
4 Harry 102 M.A M 4 1500 390 490 30
5 Sumit 103 B.Tech M 5 8000 900 900 80
1.To list the names of those employees whose name which starts with ‘H’.
2.To display the name of the employee who has the maximum basic.
3. To display the number of employees department wise.
4. To add the new column named Total_Sal to the salary table.
5.To display all male employees whose Basic is greater than 2000.

9. Write SQL commands for the following on the basis of Bank relation given below:

Acc_No Cname Bname Amount Transactions Dateofopen


1 Karan Bank Of Boroda 15000 10 12/01/98
2 Puneet State Bank 25000 09 1/2/97
3 Anirban Oriental Bank 17000 05 15/7/99
4 Yatin Standard Charted 38000 11 10/02/99
5 Sunny State Bank 47000 15 06/02/98
6 Jayant Uco Bank 34000 07 10/08/98
7 Nikhil Bank Of Boroda 56000 12 01/01/99
8 Tarun Oriental Bank 22000 08 04/04/99
9 Jisha Uco Bank 34500 11 05/01/98

1.Display data for all customers whose transactions are between 8 and 11.
2.Display data for all sorted by their dateofopen in descending order.
3.To count number of customers with amount<30000.
4.List the minimum and maximum amount from the bank.
5.To list Cname , Bname ,amount for all the clients whose amount is <20000.

7
********************************

You might also like