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

Python Practical List Xii 2019-2020

The document contains 21 practical programming problems related to computer science. The problems cover a range of topics including password validation, number processing functions, prime and perfect number checks, plotting graphs, sorting/searching lists, file handling, NumPy array processing, GUI applications, cryptography, web scraping, stacks, queues, and a Django calculator and user registration app. The problems increase in complexity and cover fundamental programming concepts as well as integration of Python libraries and frameworks.

Uploaded by

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

Python Practical List Xii 2019-2020

The document contains 21 practical programming problems related to computer science. The problems cover a range of topics including password validation, number processing functions, prime and perfect number checks, plotting graphs, sorting/searching lists, file handling, NumPy array processing, GUI applications, cryptography, web scraping, stacks, queues, and a Django calculator and user registration app. The problems increase in complexity and cover fundamental programming concepts as well as integration of Python libraries and frameworks.

Uploaded by

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

AMITY INTERNATIONAL SCHOOL

PRACTICAL LIST 2019-20 (Final)


CLASS XII
COMPUTER SCIENCE

1) A website requires the users to input username and password to register. You have to
write a program to check the validity of password input by users based on the following
criteria. Take in a list of passwords.

Following are the criteria for checking the password:


1. At least 1 letter between [a-z]
2. At least 1 number between [0-9]
3. At least 1 letter between [A-Z]
4. At least 1 character from [$#@]
If the following string of passwords are given as input to the program:
ABd1234@1,a F1#,2w3E*,2We3345
Then, the output of the program should be:
Valid Password is - ABd1234@1
2) Write a program to input a number and then call the functions
count(n) which returns the number of digits
reverse(n) which returns the reverse of a number
hasdigit(n) which returns True if the number has a digit else False
show(n) to show the number as sum of place values of the digits of the number.
(eg 124 = 100 + 20 + 4)
3) A Number is a perfect number if the sum of all the factors of the number (including 1)
excluding itself is equal to number.
For example: 6 = 1+2+3 and 28=1+2+4+7+14
Number is a prime number if it 's factors are 1 and itself.
Write functions i) Generatefactors() to populate a list of factors
ii) isPrimeNo() to check whether the number is prime number or not
iii) isPerfectNo() to check whether the number is perfect number or not

Save the above as a module perfect.py and use in the program main.py as a menu driven
program.

4) Pascal’s triangle is a number triangle with numbers arranged in staggered rows such that
anr=n!/r!(n−r)!
This equation is the equation for a binomial coefficient.
Write a UDF and a Recursive function in Python to print the Pascal Triangle

5) Data can be represented in memory in different ways Binary, Decimal, Octal, and
Hexadecimal. Input number in decimal and desired type (Specify B for Binary, O for
Octal, H for Hexadecimal) for output.
Write a program using UDF to perform the conversions-
SAMPLE INPUT 12
DESIRED TYPE B
Result: 1100;
SAMPLE INPUT 25
DESIRED TYPE O
Result: 41
Convert the same function to a recursive function

6) Take in the population of 10 states in India and plot a population density pie graph
showing each state with different colour

7) Use matplotlib.pyplot.plot to produce a plot of the functions f(x) = e−x/10 sin(πx) and
g(x) = xe−x/3 over the interval [0, 10]. Include labels for the x- and y-axes, and a legend
explaining which line is which plot. Save the plot as a .jpg (“Jpeg”) file

8) Write a program to take two lists from a user and write functions to do the following:
i) Return a sorted merged list from the above list
ii) Prints sum of common elements from both the lists.
iii) Returns True if the two lists provided by user are circularly identical or False if not.

9) i) Use NumPy and write a program to create a 5x5 array with random values and find the
minimum and maximum values.
ii) Find the most frequent value in an array.
iv) Find the closest value (to a given scalar) in an array

10) Create a graphical application for Simple Interest Calculator that accepts user inputs for
P, R and T. Calculate Simple Interest writes the output using a message box on the screen.
Use the tkinter library.

11) Write a program to input a list and write the function for the following:
i) To sort list using bubble sort and find efficiency
ii) To search an element using binary search and find efficiency
iii) To search an element using linear search and find efficiency

12) Write a function to create a text file containing following data:


Neither apple nor pine are in pineapple. Boxing rings are square.
Writers write, but fingers don’t fing. Overlook and oversee are opposites.
A house can burn up as it burns down. An alarm goes off by going on.

a) Read back the entire file content using read( ) or readlines( ) and display on the
screen.
b) Append more text of your choice in the file and display the content of file with
line numbers prefixed to line.
c) Display last line of file.
d) Display first line from 10th character onwards.
e) Read and display a line from the file. Ask user to provide the line number to be
read.
f) Find the frequency of words beginning with every letter i.e.
(for the above example)
Words beginning with a: 5
Words beginning with n: 2
Words beginning with p: 2
Words beginning with o: 5 and so on

13) Assume that a text file named file1.txt contains some text, write a function named
isvowel( ) that reads the file file1.txt and creates a new file named file2.txt, which shall
contain only those words from the file file1.txt which don’t start with a vowel
For example, if the file1.txt contains:
Carry Umbrella and Overcoat When it Rains
Then the file file2.txt shall contain
Carry When Rains

14) A file containing data about a collection of students has the following format.
Rajat Sen 12345 1 CSEE
Jagat Narain 13467 3 CSEE
Anu Sharma 11756 2 Biology
SumitaTrikha 23451 4 Biology
SumderKumra 11234 3 MME
KantiBhushan 23211 3 CSEE
Each line contains a first name, a second name, a registration number, no of years and a
department separated by tabs.
a) Write a Python program that will copy the contents of the file into a list of tuples
b) Display full details of the student sorted by registration number
· The names of all students with no of year less than 3
· The number of people in each department

15) Write is a program that reads a file“myfile.txt” and builds a histogram (a dictionary having
key value pair as word: occurrence) of the words in the file.
a) Now use histogram to print
i) Total number of words
ii) Number of different words
iii) The most common words
b) Using above text file “myfile.txt”, write a program that maps a list of words read
from the file to an integer representing the length of the corresponding words.( use
dictionary having key value pair as length : list of word )
Now using above dictionary design a function find_longest_word() to display a list of
longest words from file.
Define a function filter_long_words(n) that takes an integer n and returns the list of
words that are longer than n from file.
Using above function create another file “newfile.txt” by filtering out all words
returned by function filter_long_words(8)

16) In cryptography, a Caesar cipher is a very simple encryption techniques in which each
letter in the plain text is replaced by a letter some fixed number of positions down the
alphabet. For example, with a shift of 3, A would be replaced by D, B would become E,
and so on. The method is named after Julius Caesar, who used it to communicate with his
generals. ROT-13 ("rotate by 13 places") is a widely used example of a Caesar cipher
where the shift is 13.

For eg if key is 13 then in Python, the key for ROT-13 may be represented by means of
the following dictionary:

key = {'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u', 'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z',
'n':'a', 'o':'b', 'p':'c', 'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j', 'x':'k', 'y':'l', 'z':'m', 'A':'N',
'B':'O', 'C':'P', 'D':'Q', 'E':'R', 'F':'S', 'G':'T', 'H':'U', 'I':'V', 'J':'W', 'K':'X', 'L':'Y', 'M':'Z',
'N':'A', 'O':'B', 'P':'C', 'Q':'D', 'R':'E', 'S':'F', 'T':'G', 'U':'H', 'V':'I', 'W':'J', 'X':'K', 'Y':'L',
'Z':'M'}
Assume a key is a single digit signed integer. To manage encoding, create a dictionary
having key as an alphabet and value is the equivalent encoded alphabet.
Select suitable option from user whether he wishes to encode/decode a text file. Read
input file and create output file after encoding / decoding it using the dictionary created.

17) Use urllib3 module

Open url = "https://www.pythonforbeginners.com/"


Now do the following -
Print header, date, server
Read all the data and print it line by line
Copy content of the page to a file ‘downloaded.htm’

18) Create a stack to take in stack of numbers and then simulate a ring game.

A ring stand is such that only a ring of higher diameter can be placed on lower one. The
diameters are given by the user the program will compare the diameter of ring at stack top
with the diameter of ring to be placed if condition specified is true ring is added to the
stack otherwise keep popping and put them into temporary ring stand to arrange them into
specific order.

19) Create a program to take in a list reg_no, Name,admission_to_class (Nursery, KG, I) and add
member functions to

i) Add data to the queue.


ii) Display length of the queue.
iii) Print a report showing number of applications received for admission to each class.
20) Create a Django app to create a calculator, for addition, subtraction, multiplication, and
division

21) Write a python program with Django, Connect the database, take username and details,
store them in the database. If another user gives same details, render a new HTML page and
show user is already existing.

DATABASE MANAGEMENT (MySQL +Python)

1. Consider the following TEACHER and SALARY table and Write the command in MYSQL for (i) to (v):
Table: TEACHER

Table: SALARY
SID BASIC ALLOWANCE DA
101 12000 1000 300
104 23000 2300 500
107 32000 4000 500
114 12000 5200 1000
109 42000 1700 200
105 18900 1690 300
130 21700 2600 300
i. Display NAME and DA of all staff who are in Accounts department and having more than 10
years of experience and DA is more than 300.
ii. Display the NAME, SID and basic of all staff working in physics department.
iii. Increase the experience of computer dept by 2 years.
iv. Display maximum and minimum Basic Salary from the SALARY table.
v. Delete Salary table
2. Consider the following WATCHES and SALE table and Write the command in MYSQL for (i) to (v):
Table: WATCHES
Watchid Watch_Name Price Type Qty_Store
W001 High Time 10000 Unisex 100
W002 LifeTime 15000 Ladies 150
W003 Wave 20000 Gents 200
W004 High Fashion 7000 Unisex 250
W005 Golden Time 2500 Gents 100

Table: SALE
WatchId Qty_Sold Quarter
W001 10 1
W003 5 1
W002 20 2
W003 10 2
W001 15 3
W002 20 3
W005 10 3
W003 15 4

i. To display watch name and their quantity sold in first quarter.


ii. To display the details of those watches whose name ends with ‘Time’?
iii. To display total quantity in store of Unisex type watches.
iv. To display watch’s name and price of those watches which have price range in
between 5000-15000.
v. To display Quantity sold of all watches WatchId wise.
3. Consider the table “ITEM” having the following fields
Itemcode varchar

Itemname varchar

Price float
i) Create the table ITEM in the mydb database

ii) Create a menu driven program in python to have

a) function for inserting records in the table

b) function for displaying all the records from the table item

c) function for searching for a particular record on basis of Itemcode

4. Create a Table “STUDENT” in MySQL with the following attributes.

Table: STUDENT

ColumnName Datatype Size Constraint


RollNo Number Primary Key
Name Varchar 30 Not Null
Class Number
DOB Date
Gender Varchar 2

i) Create a menu driven program in Python for the user to enter the details and save
the data in MySQL table
ii) Allow the user to update the details for a particular rollno and ensure the changes
have been made in the table student.

5. Create a Table “BUS” in MySQL with the following attributes.

Table: BUS
ColumnName Datatype Constraint
BusNo Number Primary Key
Origin Varchar
Dest Varchar
Rate Number
Km Number

Now build a connection with Python to add a new record and Display the details in above table.
Use Tkinter to create the front end.

You might also like