Adobe Scan 16 Nov 2024
Adobe Scan 16 Nov 2024
-IIPr/
DSE-B-2PICBCSIBatch-2
2022
HONOURS PRACTICAL
COMPUTER SCIENCE
Paper : DSE-B-2P
(Programming in Python Lab)
Full Marks : 30
Batch -2
as product name and price. For this, it asks user to
1. Write a program in Python that reads data values a dictionary whose keys are the product
enter such data pairS until user says 'n'/no. Store these data in
entering products and prices, allow them
names and whose values are the prices. When the user is done
or a message if the product is not in the data.
to enter a product name and print the corresponding price the products whose price is within that range.
Also, allow the user to enter price range and print out all
Take at least 8 such data.
3. Write aclass in Python called PyConverter. User willpass alength and aunit when declaring an object
from the class, for example ob =PyConverter (9, 'meters'). Consider units to be kilometers, meters and
centimeters. For each of these units there should be a method that returns the length output converted
into those units. For example, using the PyConverter object if the user calls ob.centimeter), he should
get 900as the result.
2022
COMPUTER SCIENCE HONOURS PRACTICAL
Paper : DSE-B-2P
(Programming in Python Lab)
Full Marks : 30
1. Write a program in Python to create a Graph' class to store and manipulate graphs. It should have the
following functions :
) Read an edge list file, where each edge (u, v) appears exactly once in the file as space
separated values.
(ii) Add and remove nodes and edges
(ü) Print nodes, and edges in a user readable format
(iv) Find all the neighbours of a node.
2. Write a program Python to implement a queue using list. Must incorporate the functions for
add-element( ) delete element( ), list full() and list empty( ).
3. Given astring write a program in Python to find the occurrences of every character, number, special
character, punctuations etc.
4. Write a Python program to find all anagrams of a string in a given list of strings using lambda.
Original list of strings:
('bcda', 'abce', 'cbda', 'cbea', adcb']
Anagrams of 'abcd' in the above string:
['bcda', 'cbda', 'adcb']
6. Atext file named "matter.txt" contains some text, which necds to be displayed such that every next
character is separated by asymbol "" and if there is aspace it is to be replaced by 'S". Write a function
definition for hash display() in Python that would display the entire content of the file matter.txt in the
desired format.
Example :
If the file matter.txt has the following content stored in it:
THE WORLD IS ROUND
7. Write a Python program that accepts a hyphen-separated sequence of words as input and prints the
words in a hyphen-separated sequence after sorting them alphabetically.
Sample Items : green-red-yellow-black-white
Expected Result : black-green-red-white-yellow.
8. (a) Write a Python program to print the following pattern. In the following output (n =3)
Armstrong.
(b) Write a Python program to check whether a given number is
X(Sth Sm.)-(ompter.Sc.-IIPr:l
(2) DSE-B-2PICBCSIBatch-2
4. Write a program in Python to nsc the file data.txt for solving and displaying outputs the following tasks
after reading it:
(a) All vords ending with on"
b) All words whose second and third letters are " and "e"
(c) All words with no vowcls.
5. Write a program in Python that populates an empty list with integers, each which are either 0 or 1. Then
find the size of the longest chain of zeros. Also give the span of indices containing the longest chain.
For example,
the longest run of zeros in [1,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1] is 6.
span: 7 to 12
6. Write functions in Python called number _offactors() and list of factors( ) that take apositive integer
and do the following:
(a) number of factors(val) : returns a list of its factors
(b) list of factors(val):returns how many factors the number has.
Check if input is positive and report if not.
7. (a) Write a program in Python to find all numbers between 1 and N those are divisible by 7 and end
in 6. Also display their count.
For example : if N= 60, list of numbers : [56], count = 1.
(b) Write a program in Python to input different names in any case. Now convert the upper case letters
to lower case letters and lower case letters to upper case letters.
2022
Batch - 1|
multiplication by
program to perform matrix addition, matrix subtraction, and matrix
3. Write a Python operation.
may use separate functions for each
simulating matrix as a list of lists. You
contents of
filenames as command line arguments. Then copy
to accept two line at the end
4. Write aPython program number to the beginning of each line and length of the
another adding line
one file into checks wherever applicable.
of each line. Incorporate validation
operations
6. Write aPython program to simulate stack data structure using lists. Include standard stack
like push(), pop (), peek () and is empty ().
7. Write a recursive function that finds the H.C.F. of two numbers passed as arguments. Then write a
and the fifth elements.
Python program to input a list of integers, intlist[]| and find the H.C.F. of the first
Zero Division Error and Value
The program should handle errors like Name Error, Index Error,
Error.
1. Write a program in Python that reads data values as product name and price. For this, it asks user to
enter such ata pairs untl user says 'n'no. Store these data in a dictionary whose keys are the product
names and whose values are the prices. When the user is done entering products and prices, allow them
to enter a product name and print the corresponding price or a message if the product is not the data.
Also, allow the user to enter price range and print out all the products whose price is within that range.
Take at least 8 such data.
A Writen nrogram in Python to use the file data.txt for solving and displaying outputs the following tasks
after reading it:
(a) All words cnding with "on"
(b) Al words whose second and third letters are " and "
5. Write a program in Python that populates an empty list with integers, each which are either 0or 1. Then
find the size of the longest chain of zeros. Also give the span of indices containing the longest chain.
For example,
the longest run of zeros in [1,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1] is 6.
span: 7 to 12
a positive integer
6. Write functions in Python called number of factors( ) and list of factors( ) that take
and do the following :
factors
(a) number of factors(val):returns a list of its
number has.
(b) list of factors(val):returns how many factors the
Check if input is positive and report if not.
9. Write aprogram in Python to find a pair of clements (index pair) from a given array numbers whose
sum cquals a given target mumber. This target value is an user input. Report if a solution is found or not.
Note that. there can be more than one solutions for a target input, so break out when one of them is
found.
Input : numbers = (10, 30, 20, 40, 50, 60, 70], target = 50
Output : 0, 3
1, 2
10. Write a program in Python that has a class namely PyWords. It has a field namely process-words that
can store a list of words. The user of the class should pass a list of words as input to the class.
There should be functions to solve the jobs given below:
(a) words_with length(1) returns a list of all the words of length 1
(b) starts with(s) returns a list of all the words that start with s
(c) palindromes() returns a list of all the palindromes in the list, report if no palindrome exists in
list.
X(Sh Sm) (ompter Se. HPel
DSE-R-)PICRCS/Botrht
2022
COMPUTER SCIENCE HONOURS PRACTICAL
P'aper : DSE-B-2P
(Programming in Python Lab)
Full Marks : 30
1. Write a program in Python to create a 'Graph' class to store and manipulate graphs. It should have the
following functions
) Read an edge list file, where each edge (u, v) appears exactly once in the file as space
separated values.
(i) Add and remove nodes and edges
(ii) Print nodes, and edges in a user readable format
(iv) Find all the neighbours of a node.
2. Write aprogram Python to implement a queue using list. Must incorporate the functions for
add-element( ) delete element( ), list full( )and list empty().
3. Given astring write a program in Python to find the occurrences of every character, number, special
character, punctuations etc.
4. Write a Python program to find all anagrams of a string in a given list of strings using lambda.
Original list of strings:
['beda', abce', cbda', cbea', 'adcb]
Anagrams of 'abcd' in the above string:
['bcda', 'cbda', 'adcb']
6
A text filc namcd "matter txt contains
CharacteT IN separated b a svnbol andsome text which nceds to be
ifthere is a space it is to be displaved such that every next
definition for hash displav() in Pvthon that would replaced by $ Write a funetion
desired format display the entire content of the file matter txt in the
Examplc
If the file matter. txt has the
following content stored in it
THE WORLD IS ROUND
The function hash display() should display the
following content :
T#H#ESW#0#R#h#DSl#SSR#O#U#N#D#
7. Write a Python program that accepts a hyphen-separated sequence of words as input and prints the
words in ahyphen-separated sequence after sorting them alphabetically.
Sample ltems : green-red-yellow-black-white
Expected Result : black-green-red-white-yellow.
8. (a) Write aPython program to print the following pattern. In the following output (n =3)
k
2022
COMPUTER SCIENCE HONOURS PRACTICAL
Paper : DSE-B-2P
(Programing in Python Lab)
Full Marks : 30
Answer any one question.
Batch - 4
from alist.
1. (a) Write aPython function to remove all occurrences of a given item
common
and returns True' if they have at least one
(b) Write aPython function that takes two lists
member.
operations on a set.
2. (a) Write aPython program to perform the following
) union operation
() intersection operation
(üi) set difference operation
number in a set.
(b) Write a Python program to find maximum
4. (a) Write a Python program to count Even and Odd number in a List.
9. (a) Write a Python program to reverse order of the words of a given string Example.
Input str = "my name is lucky"
output str = "lucky is name my"
(b) Write a Python program to get the number of occurrences of a specified element in an array.
10. A binary file Book.dat" has structure [BookNo, Book Name, Author, Price].
(a) Write auser defined function in Python create File) to input data for a record and add to Book.dat.
(b) Write a function countRec(Author) in Python which accepts the Author name as parameter and
count and return number of books by the given Author are stored in the binary file Book.dat".