Python Modulewise Questions
Python Modulewise Questions
205B
Modulewise important questions
Module I
1. What is a flow control statement? Discuss if and if-else statements
with flow chart.
2. What is an arithmetic expression? What is the output of this statement?
“world are” – Explain the reason if the statement produces an error.
3. Write a Python program to add ‘n’ numbers accepted from the user.
4. With Python programming examples, explain continue and break
statements with their syntax and control flow diagrams.
5. Write a function to calculate factorial of a number. Develop a program
to compute binomial coefficient (Given N and R).
6. Explain looping control statements in Python with syntax and example
for each.
7. Develop a Python program to generate Fibonacci Sequence of length N
(read N from the console).
8. Explain two ways of importing modules with syntax and example.
9. Explain four scope rules of variables in Python.
10. Write a function named DivExp which takes two parameters a, b and
returns a value (c = a // b). Write suitable assertion for a > b in function
DivExp and raise an exception for when b = 0. Develop a Python
program which reads two values from the console and calls a function
DivExp. (Lab program)
11. Discuss various methods of importing modules in Python programs.
Which method is best? Explain.
12. What is the lambda function? Explain with an example of addition of
two numbers.
13. How can you prevent a Python program from crashing? Discuss
different ways to avoid crashing.
14. Explain the math operators in Python from highest to lowest
precedence with an example for each. Write the steps how Python is
evaluating the expression:
(5 - 1) + ((17 // 3) ** 2) and reduces it to a single value.
15. Explain Local and Global Scope in Python Programs. What are
local and global variables? How can you force a variable in a function to refer
to the global variable?
16. What are comparison and Boolean operators? List all the comparison
and Boolean operators used in Python and the type of operations with
suitable examples.
18. List and explain the syntax of all flow control statements with
example.
22. List the features of Python programming language (at least 5). (5M)
26. Explain elif, for, while, break and continue statements with example
for each. (10M)
27. Explain the concept of type conversion functions and math functions
in Python with examples.
30. List and define the use of comparison operators in Python. Write the
output of following expressions:
i) 2 == 3
ii) 20 > 6
iii) 20 / 6
31. Explain the three type conversion functions in Python with suitable
example.
35. Write a Python program to find the largest of 3 numbers and check
whether the given year is a leap year or not
Module II
1. Explain with examples the use of dictionary methods:
o get()
o setdefault()
2. Develop Python programs using nested lists. Explain copy(),
copy.copy(), and copy.deepcopy() methods.
3. Explain append() and index() functions with respect to lists.
4. Explain different ways to delete an element from a list with syntax and
examples.
5. Read a number (as chars) from the console and print the frequency of
each digit.
6. Explain why tuples are immutable with examples.
7. Discuss list and dictionary data structures with examples.
8. Write a Python program to accept numbers and store only ODD
numbers in a list.
9. For a = [10, 20], predict the output of:
o print(a)
o print(a[0])
o print(a[1])
o print(a[:])
10. Write a Python program to read dictionary data and delete any given
key entry.
11. Explain different clipboard functions in Python used in Wiki markup. (6m)
12. Using string slicing operation, write Python program to reverse each
word in a given string (e.g., input = "hello how are you", output = "olleh
woh era uoy") (6m)
13. For a given list num = [45, 22, 14, 65, 97, 72],
write a Python program to replace all the integers divisible by 3 with "PPP"
and all integers divisible by 5 with "999" and replace the integers divisible
by both 3 & 5 with "PPP999" and display the output.(6m)
14. What are the different methods supported in Python list? Illustrate all
the methods with an example. (8m)
15. What is a dictionary? Illustrate with an example Python program the
usage of nested dictionary.
16. List out all the useful string methods which support is in Python.
Explain with an example for each method.(10M - modules)
17. What are the ways of traversing a list? Explain with an example for
each.
18. How is tuple different from a list and which function is used to convert
list to tuple?
19. Differentiate between list and dictionary.
20. How is dictionary different from list? Assume a dictionary consisting of
population by key & value respectively. Write a program to traverse the
dictionary and display the most populated city.
21. Write a Python program to read dictionary data and delete any given
key entry in the dictionary.
22. Demonstrate
i) How a dictionary items can be represented as a list of tuples
ii) How tuples can be used as keys in dictionaries?
23. What is the difference b/w copy.copy() and copy.deepcopy() function
applicable to a list or dictionary in Python? Give a suitable example for
each.
24. Discuss get(), items() and values() dictionary methods in Python with
examples.
25. Explain with a programming example to each
i) in
ii) get()
iii) setdefault()
26. What is a dictionary? Illustrate with an example Python program the
usage of nested dictionary.
27. Explain Data Structures to model real-world things.
Module III
1. Explain Python string handling methods with examples:
split(), endswith(), ljust(), center(), lstrip() (10M)
2. Explain reading and saving Python program variables using
shelve module with suitable Python program. (6M)
3. Develop a Python program to read and print the contents of a
text file (4M)
4. Explain Python string handling methods with examples:
join(), startswith(), rjust(), strip(), rstrip() (10M)
5. Explain with suitable Python program segments:
i) os.path.basename()
ii) os.path.join()
6. Develop a Python program to find the total size of all the files
in the given directory (6M)
7. Discuss different path forms of file system. (6M)
8. Explain how to read specific lines from a file? Illustrate with
Python program. (8M)
9. What is logging? How this would be used to debug the Python
program? (6M)
10. What is the use of ZIP? How to create a ZIP folder explain.
11. Write an algorithm to implement multi clipboard
functionality (6M)
12. Write a Python program to open a file and read from the
file (8M)
13. Explain mutable and immutable data-type with examples
14. Use keys(), values() and items() methods in dictionary
with an example
15. Explain case insensitive comparison method used in
strings
16. Explain password locker project with an example
17. Develop a program to find 10 most frequently appearing
words in a text file (Lab Program – 5)
18. Develop a Python program to sort the contents of a text
file and write the sorted contents in to a separate text file.
(Lab Program – 6)
19. Explain reading and saving Python program variables
using shelve module with suitable Python program.
20. Develop a Python program to read and print the
contents of a text file
21. Explain project adding bullets to wiki markup
22. Explain the isX() methods in strings
23. Write the difference between absolute path and relative
path
Module IV
1. Explain permanent delete and safe delete with a suitable Python programming
example to each. (08M)
2. Develop a program to back up a given folder into a zip file by using relevant modules
and suitable methods. (Lab Program – 7)
3. Explain the role of Assertions in Python with a suitable program.
4. Explain the functions with examples:
i) shutil.copytree()
ii) shutil.move()
iii) shutil.rmtree()
5. Develop a Python program to traverse the current directory by listing sub-folders
and files.
6. Explain the support for logging with logging module in Python.
7. Develop a function named DivExp which takes 2 parameters a, b and return a value
8. If b is zero then raise an error for a log-in function DivExp and raise an exception for
DivExp.
9. Develop a program which reads 2 values from console and calls the function DivExp.
(Lab Program – 8)
10. What is traceback? Explain with example.
11. Describe the concept of logging. Also discuss the levels of logging.
12. How to organize a file using shutil module?
13. Explain the working directory of a file and the print.format() function.
14. Explain how exceptions are handled in Python and folders performing operations.
15. What are command line tools?
16. Explain walking a directory tree in detail and write Python program to move all
files into a new directory name.
17. What are the key properties of a file?
Explain initial directory and file writing process with an example Python program.
Module V
1. Explain the methods __init__ and __str__ with suitable code
example to each
(06M)
2. Explain the program development concept 'prototype and
patch' with suitable example
3. Define a function which takes two objects representing
complex numbers and returns new complex number with
addition of two complex numbers.
Define a class “Complex” to represent the complex number.
Develop a program to read N (N >= 2) complex numbers and to
compute the addition of complex numbers (Lab Program – 9)
4. Explain the following with syntax and suitable code snippet:
i) Class definition
ii) Instantiation
iii) Passing an instance (or objects) as an argument
iv) Instances as return values
5. Define pure function and modifier. Explain the role of pure
functions and modifiers in application development with suitable
python programs.
6. Create a Time class with hour, min and sec as attributes.
Demonstrate how two time objects would be added. 08M
7. Discuss polymorphism and demonstrate with python program
8. What is Encapsulation?
Discuss with an example in which access specifiers are used in class
definition.
9. What is a class diagram?
Create empty class and corresponding class diagram for the following
statements:
i) Class A derives from class B and class C
ii) Class D derived from class A defined in statement
10. Explain classes, objects and attributes in python language with
example. Describe the concept of copying an object.
11. What is operator overloading?
Write a python code to overload +, -, and * operators by providing the
methods __add__, __sub__, and __mul__.
12. With suitable examples, demonstrate and explain:
i) Overriding and polymorphism with examples.
ii) Explain a programmer-defined type.
iii) Explain what an object is and how objects are mutable
13. Illustrate the concepts of inheritance and delegation with
examples.
14. Using prototype of add_timecode, explain object class
definition.