0% found this document useful (0 votes)
5 views14 pages

Adobe Scan 16 Nov 2024

The document outlines various programming tasks for a Computer Science practical exam, focusing on Python programming. It includes instructions for writing programs that involve data structures, file handling, and algorithm implementation, such as creating dictionaries, classes, and simulating stacks. Each task specifies requirements for input, output, and functionality, with examples provided for clarity.

Uploaded by

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

Adobe Scan 16 Nov 2024

The document outlines various programming tasks for a Computer Science practical exam, focusing on Python programming. It includes instructions for writing programs that involve data structures, file handling, and algorithm implementation, such as creating dictionaries, classes, and simulating stacks. Each task specifies requirements for input, output, and functionality, with examples provided for clarity.

Uploaded by

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

X(Sth Sm,)-Computer Sc.

-IIPr/
DSE-B-2PICBCSIBatch-2

2022

HONOURS PRACTICAL
COMPUTER SCIENCE
Paper : DSE-B-2P
(Programming in Python Lab)
Full Marks : 30

Answer any one question.

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.

more data of choice.


2. Here is an example dictionary. You may insert
d-[{'name':'Ram', 'phone':9434141414', 'email':[email protected]},
f'name':Laksman','phone':8434151515 ,"},
{'name':*Bharat', phone':7474161616', 'email:"[email protected]'},
{'name':"Satrughna','phone':9478171717", 'email':'[email protected]}]
Write a program in Python that reads the above dictionary and prints the following:
(a) All the users whose phone number ends in 5
(b) All the users that don't have an email address listed
(c) All the users whose phone number starts with 9

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.

Please Turn Over


X(Sth Snm.) - (omputer Sc.-III Pel
DSE-B-2PICBCS/Batch-3

2022
COMPUTER SCIENCE HONOURS PRACTICAL
Paper : DSE-B-2P
(Programming in Python Lab)
Full Marks : 30

Answer any one question.


Batch - 3

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']

Please Turn Over


X(Sth Sm.) -Computer Sc.-HPr/
(2) DSE-B-2PICBCSI Batch-!
D. Gven astringS of lower case characters. The task is to check whether the given string is
Or not. A heterogram is a word, phrase. or sentence in which no letter of the
Heterogram
alphabet occurs more than
once. Examples :
Input : S = "the big dwarf only jumps"
Output : Yes
Each letter in the string S has occured only once, Write a program in Python to perform the said task.

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

The function hash display) should display the following content :


T#H#ESW#O#R#h#DSI#SSR#0#U#N#D#

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.

8. Write a program in Python to simulate stack operations using list (PUSH,


POP, PEEP). Also check for
overflow, underflow conditions available in.a regular stack.
X(5th Sm.)- Computer Se. -HIPr.l
DSE-B-2PICBCSIBatch-1

2022

COMPUTER SCIENCE HONOURS PRACTICAL


Paper : DSE-B-2P
(Programming in Python Lab)
Full Marks : 30

Answer any one question.

Batch - 1|

takes as argument a list of integers, numlist[], and


1. Write a Python function expanding (numlist), that adjacent pair of elements strictly decreases; and
returns True if the absolute difference between each function should handle necessary
the function. The
False otherwise. Write a driver program to test
validation checks.

Example : (2, 3, 5, 9, 15, 24] returns False


[2, 3, 4, 6] returns False
[2, 10, 16, 20] returns True

range a-b, where


Python program to print all non-prime, non-Fibonacci numbers within
2. Write a line arguments.
and b are accepted as command
a

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

Please Turn Over


X(Sth Sm.)-Compter Sc. -HIPrl
(2) DSE-B-2PICBCS/Batch
Then perform the
5. Write a Pvthon program to nput two sets, ST and S2 containing names of cities.
following
(a) Find union, interscction and symmetric difference of the two sets.
(b) Display clemcnts of S1 in upper case and S2 in lower case.

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.

models length in feet and inches.


8. Write a Python program that defines a class Length, which
Include the following class methods :
be 0).
(a) A constructor that initializes length (default values will
(b) SetLength () : To set value of feet and inches.
(c) getLength ( ) : To return feet-inches in a tuple.
(d) magic method to print length.
(e) A magic method to add two lengths.

batsmen along with number of runs


9. Write a Python program that defines a dictionary to store names of 8
they have scored in international cricket. Then do the following :
(a) Sort the dictionary in descending order of runs.
(b) Display name of the batsman with maximum runs.
(c) Display only the names of batsmen.
(d) Add a new batsman.
(e) Remove the batsman having lowest runs.
(3) XSsh Sm.)-Compter Se.-HIPrl
10 Write a recursive thon nction to DSE-B-2PCBCSI Batch-1
or not The function check whether an integer passed as
should check for ertor if the argument is a magic number
(Note: Amagic number is anumber argument is not an inteoer
whose eventual sum of digits is |
Sav 1900,
Eventual Sum of 1909
|494949- 28 2+8- 10 |+0- |
Hence n, i.c. 1999 is a magic number).
X(Sth Sm.)-Computer Sc.-HIPr/
DSE-B-2PICBCSIBatch-2
2022
COMPUTER SCIENCE HONOURS PRACTICAL
Paper : DSE-B-2P
(Programming in Python Lab)
Full Marks : 30

Answer any one question.


Batch - 2|

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.

2. Here is an example dictionary. You may insert more data of choice.


d-[{'name':Ram', 'phone':9434141414', 'email':'[email protected]'.
{'name':Laksman','phone':8434151515',"},
{'name': Bharat','phone':7474161616*, 'email': [email protected]},
{'name':Satrughna','phone':9478171717", 'email':'[email protected]}]
Write a program in Python that reads the above dictionary and prints the following:
(a) All the users whose phone number ends in 5
(b) All the users that don't have an email address listed
(c) All the users whose phone number starts with 9

length and a unit when declaring an object


3. Write a class in Python called PyConverter. User will pass aConsider units to be kilometers, meters and
from the class, for example ob = PyConverter (9, 'meters), that returns the length output converted
centimeters. For each of these units there should be a method
object if the user calls ob.centimeter(), he should
into those units. For example, using the PyConverter
get 900 as the result.

Please Turn Over


X(Sth Sm.) -(ompnter Se.-IHIPrl
(2) DSE-B-2PICRCS/Batch-2

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 "

(c) Allwords with no vowvels.

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.

between 1and N those are divisible by 7 and end


7. (a) Write a program in Python to find all numbers
in 6. Also display their count.
count = 1.
For example : if N=60, list of numbers : [56],
letters
names in any case. Now convert the upper case
(b) Write a program in Python to input different upper case letters.
to lower case letters and lower case letters to

PEEP). Alsocheck for


Write a program in Python to simulate stack operations using list (PUSH, POP,
8.
overflow, underflow conditions available in a regular stack.
(3) N(Sth Sim.)-Compnter Se. -HIPr/
DSE-B-2PICRCSIBatch-2

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

Answer any one question.


Batch -3

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']

Please Turn Over


once amnle
Inpu the hg dwarf onl
Outpu imps
Iach letter in the string hac nocurted ons ryr Wite s tHv s n
Pvhom o perfor the nd k

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

(b) Write a Python progranm to check whether a given number is Armstrong.


X(Sth Sn,)-(omputer Sc.-HIPe/
DSE-B-2PICRCS/Batch-4

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

number (i.e. N) using recursion.


3. (a) Write a Python program to find the power of a
the following condition :
(b) Write a program to create a function "show employee" using
* It should accept the employee's name and salary and display both.

4. (a) Write a Python program to count Even and Odd number in a List.

(b) Write a Python function to find the length of a given string.

Please Turn Over


(2)
Writc a Nthon
output n progtam to ptint a diamond shane for a
4) DSE-R-2rRCRate
)
given mmher of row: (n the
Write a thon program to followino
check whether à nmber rime
is

6. (a) Write aPython program to calculate GCD and


LCM of two numbers.
(0) WTite aPython program to create a lambda function that adds 15 to a given
an argument. number passed in as

7. Write a Python program to implement binary search.

8. Write a Python program to implement quicksort to sort a list of numbers.

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".

You might also like