Faculty of Engineering & Technology (Coed)
Python Programming for Emerging Applications
Questions Bank
Subject: Python Application Programming Semester: IV
Subject Code: 22CS44 Academic Year: 2024-2025
Module I:
Python Basics: Entering Expressions into the Interactive Shell, The Integer, Floating-Point, and String Data Types, String Con
and Replication, Storing Values in Variables, Your First Program, Dissecting Your Program.
Flow control: Boolean Values, Comparison Operators, Boolean Operators,Mixing Boolean and Comparison Operators,
Elements of Flow Control, Program Execution, Flow Control Statements, Importing Modules,Ending a Program Early
with sys.exit().
Functions: def Statements with Parameters, Return Values and return Statements,The None Value, Keyword Arguments
and print(), Local and Global Scope, The global Statement, Exception Handling, A Short Program: Guess the Number.
Q. Questions CO PO RB Marks
No. T
1 CO1 1,2 L2 10
Explain how to Enter expressions into the interactive shell and discuss The
integer, floating-point and String Data Types
2 CO1 1,2 L2 8
Explain string concatenation and replication with an example.
3 CO1 1,2 L2 10
Describe how to store the values in python variables.
4 C01 1,2 L3 4
Write a python program to say hi and ask your name.
5 Demonstrate with example comment, print(), input(), len() and str(),int(),float()? CO1 1,2,3 L2 10
6 Explain Assignment Operators, Comparison Operatorsand Boolean Operators and CO1 1,2 L2 10
demonstrate how to mix Boolean and comparison operators in python with suitable
examples.
7 With an example describe the elements of flow control statements with its execution CO1 1,2 L3 6
steps
8 With flow chart and program showcase the different flow control statements used in CO1 1,2 L2 10
python
9 With flow chart and program showcase the different loop control statements used in CO1 1,2 L2 10
python and provide the different scenarios with range().
10 Explain snippet of importing standard library functions with two examples. CO1 1,2 L2 4
11 Write a function named collatz() that has one parameter named number. If CO1 1,2,3, L1, 6
number is even, then collatz() should print number // 2 and return this value. 5 L2
If number is odd, then collatz() should print and return 3 * number + 1.
Or
With an example demonstrate how to define a user defined function with parameters,
return values and return statements keyword arguments and print().
12 What is local and global scope and describe how Scopes matter for several reasons CO1 1,2 L3 10
with an appropriate example and explain the global statement with an
example.
13 Apply the knowledge of exception handling were we don’t want to crash the CO1 1,2 L3 8
program due to errors instead we want the program to detect errors, handle them,
and then continue to run,
i) divide by zero
ii) input validation
14 Design a python program to guess the number between 1 to 20 CO1 1,2 L2 5
15 What is the difference between break and continue? What is the difference between CO1 1,2 L2 10
range(10), range(0, 10), and range(0, 10, 1) in a for loop? Write a short program that prints
the numbers 1 to 10 using a for loop. Then write an equivalent program that prints the
numbers 1 to 10 using
a while loop.
Module II:
Lists: The List Data Type, Working with Lists, Augmented Assignment Operators, Methods, Example Program: Magic 8
Ball with a List, List-like Types: Strings and Tuples,References. Dictionaries and Structuring Data: The Dictionary Data
Type, Pretty Printing, Using Data Structures to Model Real-World Things.
Manipulating Strings: Working with Strings, Useful String Methods, Project: Password Locker, Project: Adding Bullets
to Wiki Markup
1 What are Lists? Explain the following with examples. CO2 1,2 L1 10
i) Getting Individual Values in a List with Indexes ,L
ii) Negative Indexes 2
iii) Getting Sublists with Slices
iv) Getting a List’s Length with len()
v) Changing Values in a List with Indexes
vi) List Concatenation and List Replication
vii) Removing Values from Lists with del Statements
2 Write the python to display the six cat names and then apply the knowledge of CO2 1,2 L3 10
list to show how the same program is written using the list to take the advantage
of using it.
3 How is a tuple different from a list and string ,which function is used to CO2 1,2 L1 5
convert a list to a tuple ? ,3
4 Explain the following operations with an example CO2 1,2 L2 12
i) The in and not in Operators
ii) The Multiple Assignment Trick
iii) Augmented Assignment Operators
iv) References
v) The copy Module’s copy() and deepcopy() Functions
vi) Mutable and Immutable Data Types
vii) Exceptions to Indentation Rules in Python
5 Apply the knowledge of loops with list to demonstrate the following CO2 1,2 L3 8
i) picture grid ,3
grid = [['.', '.', '.', '.', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['O', 'O', 'O', 'O', 'O', '.'],
['.', 'O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['.', '.', '.', '.', '.', '.']]
ii) To display the following output
6 Describe the different methods used on list. and design the python program for CO2 1,2 L3 10
Magic 8 ball with list
7 What are Dictionaries? Analyze how the dictionaries are created and how they CO2 1,2 L4 10
differ from list and program that counts the number of occurrences of each letter
in a string.
8 Explain items(), keys(), values(), in and not in, get(), setdefault() dictionary CO2 1,2 L2 12
methods in Python with examples.
9 Write a python program counts the number of occurrences of each letter in a string CO2 1,2 L3 10
using pprint.
10 Apply the knowledge of dictionaries to implement the A Tic-Tac-Toe Board CO2 1,2 L3 8
11 Apply the knowledge of dictionaries , which contains nested dictionaries in CO2 1,2 L3 10
order to see who is bringing what to a picnic and Fantasy Game Inventory
12 List to Dictionary Function for Fantasy Game Inventory CO2 1,2 L3 5
Imagine that a vanquished dragon’s loot is represented as a list of strings ,3
like this:dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
Write a function named addToInventory(inventory, addedItems), where
theinventory parameter is a dictionary representing the player’s inventory and
the addedItems parameter is a list like dragonLoot.
13 What are string? explain the multiple ways to type strings. CO2 1,2 L1 8
14 Explain the following with respect to strings CO2 1,2 L2 10
i) Indexing and Slicing Strings
ii) The in and not in Operators with Strings
iii) Copying and Pasting Strings with the pyperclip Module
15
Describe the methods used to analyze strings or create transformed string values. CO2 1,2 L3 10
16 Table Printer CO2 1,2 L3 6
Write a function named printTable() that takes a list of lists of strings ,3
and displays it in a well-organized table with each column right-justified.
Assume that all the inner lists will contain the same number of strings.
For example, the value could look like this:
tableData = [['apples', 'oranges', 'cherries', 'banana'],
['Alice', 'Bob', 'Carol', 'David'],
['dogs', 'cats', 'moose', 'goose']]
Your printTable() function would print the following:
Apples Alice dogs
oranges Bob cats
cherries Carol moose
banana David goose
17 Apply the knowledge of dictionaries, list and strings to develop program for CO2 1,2 L3 8
Adding Bullets to Wiki Markup ,3
18
Apply the knowledge of dictionaries, list and strings to develop a safe password CO2 1,2 L3 10
locker. ,3
Module -3
Pattern Matching with Regular Expressions: Finding Patterns of Text Without Regular Expressions, Finding
Patterns of Text with Regular Expressions,More Pattern Matching with Regular Expressions, Greedy and Nongreedy
Matching, The findall() Method, Character Classes, Making Your Own Character Classes, The Caret and Dollar Sign
Characters, The Wildcard Character, Review of Regex Symbols, Case-Insensitive Matching, Substituting Strings with
the sub() Method, Managing Complex Regexes, Combining re .IGNORECASE, re .DOTALL, and re .VERBOSE,
Project: Phone Number and Email Address Extractor.
Reading and Writing Files: Files and File Paths, The os.path Module, The File Reading/Writing Process, Saving
Variables with the shelve Module,Saving Variables with the pprint.pformat() Function, Project: Generating Random
Quiz Files, Project: Multiclipboard.
Organizing Files: The shutil Module, Walking a Directory Tree, Compressing Files with the zipfile Module, Project:
Renaming Files with American-Style Dates to European-Style Dates,Project: Backing Up a Folder into a ZIP File.
1 What is regular expression? write a python program to show the discrimination CO3 1,2 L3 10
between finding patterns of text with and without regular expression.
2 Explain the Review of Regular Expression Matching with appropriate example CO3 1,2 L3 10
3 Design the techniques used for pattern matching with regular expression CO3 1,2 L3 12
i) grouping with parenthesis ,3
ii) Matching Multiple Groups with the Pipe
iii) Optional Matching with the Question Mark
iv) Matching Zero or More with the Star
v) Matching One or More with the Plus
vi) Matching Specific Repetitions with Curly Brackets
4 With an example demonstrate the greedy and nongreedy matching in regular CO3 1,2 L2 8
expression
5 List out what are the different character classes and its representation also regular CO3 1,2 L2 10
expression symbol and its meaning along with an example
6 Write a python program to create phone number and email address by using CO3 1,2 L4 8
regular expression. ,3,
5
7 Discuss the following with an example CO3 L3 12
i) Making Your Own Character Classes
ii) The Caret and Dollar Sign Characters
iii) The Wildcard Character
iv) Matching Everything with Dot-Star
v) Matching Newlines with the Dot Character
vi) Case-Insensitive Matching
vii) Substituting Strings with the sub() Method
viii) Managing Complex Regexes
ix) Combining re.IGNOREC ASE, re.DOT ALL , and re.VERBOSE
8 write programs to do the following tasks. CO3 1,2 L4 8
i) Strong Password Detection
ii) Regex Version of strip()
9 What are the key properties of a file? Explain in detail file reading/writing CO3 1,2 L2 10
process wit an example of python program.
10 Briefly explain What are the different methods of file operations supports in CO3 1,2 L2 10
python shutil module
11 Write a python program to create a folder PYTHON and under the hierarchy 3 CO3 1,2 L4 8
files file1,file2 and file3.write the content in file1 as ”SUK” and in file2 as ,3,
“UNIVERSITY” and file3 content should be by opening and merge of file1 and 5
file2. Check out the necessary condition before write file3.
12 Describe the following with suitable python code snippet: CO3 1,2 L2 8
a) Greedy and Non greedy pattern matching
b) Find all() method of regex object
13 a) How do we specify and handle Absolute Relative path? CO3 1,2 L1 5
14 What is meant by compressing files? Explain reading, extracting and creating CO3 1,2 L2 10
ZIP files with code snippet
15 With code snippet, explain saving variables using the shelve modules and pprint CO3 1,2 L3 6
(),pformat() functions.
16 Write a program that reads a string with five characters which starts with ‘a’ CO3 1,2 L4 6
and ends with ‘z’. Print search successful if pattern matches string. ,3,
5
17 Discuss the following methods of os module i)chdir ii)rmdir iii)walk iv)listdir CO3 1,2 L2 8
18 Demonstrate the use of Regex symbols with an appropriate example CO3 1,2 L2 10
19 Use the date time module to write a program that gets the current date and CO3 1,2 L3 6
prints the day of the week. ,3
Module 4
Classes and objects: Programmer-defined types, Attributes, Rectangles, Instances as return values, Objects are
mutable, Copying.
Classes and functions: Time, Pure functions, Modifiers, Prototyping versus planning.
Classes and methods: Object-oriented features, Printing objects, Another example, A more complicated example,The
init method, The __str__ method, Operator overloading, Type-based dispatch, Polymorphism, Interface and
implementation.
Inheritance: Card objects, Class attributes, Comparing cards, Decks, Printing the deck, Add, remove, shuffle and
sort, Inheritance, Class diagrams, Data encapsulation.
1 Define class and object. Give an example for creating a class and an object of C04 1,2,5 L1 06
that class.
2 Write following functions and demonstrate the working of these functions by CO4 1,2,3, L4 10
5
creating suitable objects.
To read attribute values
To display point as an ordered pair
To find distance between two points
To find the midpoint of two points
To find reflex of the point about x-axis i.e., it must return a new
point
object
3 CO4 1,,2,3 L2 10
Briefly discuss self keyword in python ,5
4 Explain operator overloading and polymorphism with examples CO4 1,2 L2 08
5 Differentiate pure functions and modifiers with suitable examples CO4 1,2,3, L5 06
5
6 Write a program to create a class called Rectangle with the help of a corner CO4 1,2,3, L4 06
5
point, width and height. Write following functions and demonstrate
their working: To find and display center of rectangle
To display point as an ordered pair
To resize the rectangle
To find area and perimeter of a rectangle
7 With help of programming examples explain the difference between Prototype CO4 1,2,3, L2 06
5
and Planned Programming Development.
8 Write a program to create a class Time to represent time in HH:MM:SS CO4 1,2,3, L3 06
5
format. Perform following operations:
a.Overload + to add two time objects
b. Overload + to add a numeric value to a time object
(commutative)
c. Overload __str__() to display time in appropriate format
9 Write a note on data encapsulation with example CO4 1,2,3 L1 08
10 CO4 1,2,3, L2 10
Illustrate the concepts of inheritance and class diagram with examples
5
11 Differentiate copy.copy() and copy.deepcopy() with suitable examples. CO4 1,2.3 L5 06
12 Discuss the functions isinstance(),hasattr() with suitable examples. CO4 1,2,5 L2 06
13 With example explain type-based dispatch. CO4 1,2,5 L2 08
14 Write a program to add two point objects by overloading + operator. CO4 1,2,3, L4 06
5
Overload __str__() to display point as an ordered pair.
15 Discuss the significance of __init__() method in Python with a proper example code CO4 1,2.3 L2 06
snippet
16 i) make a use of the functions is instance (), hasaltr () explain with examples ii) Write CO4 1,2.3 L3 06
a program to add two-point objects by overloading + operator overload – str-() to
display point as an ordered pair
In Module-5: Introduction to NumPy:Introduction, Array, NumPy Array, Indexing and slicing, Operations on Arrays,
Concatenating Arrays, Reshaping Arrays, Splitting Arrays, Statistical operations on Arrays, Loading Arrays from files,
saving NumPy Arrays in files on disk.
Pandas and Data Visualization:Introduction to Python Libraries, Series, DataFrame, Importing and exporting
data between CSV Files and DataFrames, Pandas series Vs NumPy ndarray.
RBT: L1, L2, L3
1. CO5 1,2,3, L4 8
Bring out the differences between the numpy array and lists 5
2. CO5 1,2,3, L2 10
Discuss the different ways to create the numpy array with an example 4
3. CO5 1,2,3, L2 10
Discuss with an example Attributes of NumPy Array. 5
4. Create the following NumPy arrays: CO5 1,2,3, L3 6
a) A 1-D array called zeros having 10 elements and all the elements are set to zero. 4
b) A 1-D array called vowels having the elements ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’.
c) A 2-D array called ones having 2 rows and 5 columns and all the elements are set to
1 and dtype as int.
d) Use nested Python lists to create a 2-D array called myarray1 having 3 rows and 3
columns and store the following data: 2.7, -2, -19 0, 3.4, 99.9 10.6, 0, 13
e) A 2-D array called myarray2 using arange() having 3 rows and 5 columns with start
value = 4, step size 4 and dtype as float.
5. Using the following array write command for the following: array CO5 1,2,3, L3 6
([[10, 11, 12, 13], 5
[14, 15, 16, 17],
[18, 19, 20, 21]])
a) Find the sum of all elements.
b) Find the sum of all elements row-wise.
c) Find the sum of all element’s column-wise.
d) Find the max of all elements.
e) Find the min of all elements in each row.
f) Find the mean of all elements in each row.
g) Find the standard deviation column wise.
h) Find the transpose of a given matrix
6. write a python program to perform the following: CO5 1,2,3, L1 10
a) Add two arrays 5
b) subtract two arrays
c) Multiply two arrays
d) division of arrays
7. Write a python code to create the array having 1) 5 integers 2) 4 floating numbers 3) 5 CO5 1,2,3, L4 8
8–bit integers. 5
8. Consider the following Series object, CO5 1,2,3, L4 6
5
IP 95
PTHSICS 89
CHEMISTRY 92
MATHS 95
i. Write the Python syntax which will display only IP.
ii. Write the Python syntax to increase marks of all subjects by 10.
Given the following Series S1 and S2: CO5 1,2,3, L4 6
S1 S2 5
A 10 A5
B 20 B4
C 30 C6
D 40 D8
Write the command to find the multiplication of series S1 and S2
9 Consider two objects a and b. a is a list whereas b is a Series. Both have values CO5 1,2,3, L5 6
10,20,25,50. 5
What will be the output of the following two statements considering that the above
objects have been created already
a. print(a*2)
b. print(b*2)
Justify your answer.
10. Discuss about accessing elements of a series in pandas CO5 1,2,3 L2 10
11. How to perform mathematical operations on series in pandas ?explain with example. CO5 1,2,3 L1 10
12. Demonstrate creation of data frame with example any three CO5 1,2,3 L2 10
13. How to create Importing and exporting data between CSV Files and Data frames CO5 1,2,3 L2 10
explain it with example.
14. Consider a series object s10 that stores the number of students in each section of class CO5 1,2,3, L4 6
12 as shown below. First two sections have been given task for selling tickets @ 5
Rs.100/- per ticket as a part of social experiment. Write code to create the series and
display how much section A and B have collected.
A 39
B 31
C 32
D 34
E 35
15 Consider the following Series object, “company” and its profit in Crores CO5 1,2,3, L4 6
TCS 350 5
Reliance 200
L&T 800
Wipro 150
i. Write the command which will display the name of the company having profit>250.
ii. Write the command to name the series as Profit.
16 CO5 1,2,3, L4 8
Determine the different ways to create the numpy array with an example. 5
17 Discuss with example attributes of numpy array CO5 1,2,3 L2 10
18 Discuss about accessing elements of a series in pandas CO5 1,2,3 L2 10