BANGALORE INSTITUTE OF TECHNOLOGY
An Autonomous Institute under VTU, Belagavi
K. R. ROAD, V. V. PURA, BENGALURU-560 004
MODULE QUESTION BANK
Batch: 2024-2028 (EVEN)
Course Title: Introduction to Python Programming
Course Code : BPLCK205B
and it’s Applications
Sem: II
MODULE 1
1. Demonstrate with example print(), input() and string replication.
2. Explain elif, for, while, break and continue statements in Python with examples of each
3. Write a Python program to check whether a given number is even or odd
4. Demonstrate the concept of exception. Implement a code which prompts user for Celsius tempera-
ture, convert the temperature to Fahrenheit, and print out the converted temperature by handling the
exception.
5. List the rules to declare a variable in Python. Demonstrate atleast three different types of variable us-
es with an example program.
6. Write a Python Program to find the best of two test average marks out of three test’s marks accepted
from user.
7. Predict the output and justify the answer:
(i) 11%9 (ii) 7.7//7 (iii) (200-70)*10/5 (iv) not “False” (v) 5*1**2
8. Demonstrate the use of break and continue Keywords in looping structures using a snippet of code.
9. 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) * ((7 + 1) / (3 - 1)) and reduces it to a
single value.
10. 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?
11. What are Comparison and Boolean operators? List all the Comparison and Boolean operators in Py-
thon and explain the use of these operators with suitable examples.
12. Define a Python function with suitable parameters to generate first N Fibonacci numbers. The first
two Fibonacci numbers are 0 and 1 and the Fibonacci sequence is defined as a function F as Fn =
Fn-1 + Fn-2. Write a Python program which accepts a value for N (where N >0) as input and pass
this value to the function. Display suitable error message if the condition for input value is not fol-
lowed.
13. What is Exception Handling? How exceptions are handled in Python? Write a Python program with
exception handling code to solve divide-by-zero error situation.
MODULE 2
1. What is list? Explain append (),insert() and remove() methods with examples.
2. How is tuple different from a list and which function is used to convert list to tuple.
3. Create a function to print out a blank tic-tac-toe board.
4. Discuss get(),item(),keys(), and values() dictionary methods in python with examples.
5. With the example code explain join() and split() string methods.
6. Develop a program to accept a sentence from user and display the longest word of that sentence
along with its length.
7. Write a python program to count the number of occurrences of a given word in a file.
8. List the methods associated with the strings and explain each of them with the examples.
9. Write the Python program that accepts a sentences and build dictionary with LET-
TERS,DIGITS,UPPERCASE,LOWERCASE as keys, and there count in the sentences as values.
Ex: Sentence= ”BIT@234Institute”
D={“LETTERS”: 12,”DIGITS”:3,”UPPERCASE”:3,”LOWERCASE”:8}
10. Compare and contrast list and tuples
11. Demonstrate
i)How dictionary items can be represented as a list of tuples.
ii) How tuples can be used as keys in dictionaries?
12. List a merits of dictionary over a list? Write a python program to accept USN and Marks obtained,
find maximum, minimum and students USN who have scored in the range 100-85,85-75,75-60 and
below 60 separately.
13. Explain the concept of list slicing and list traversing with example
14. Explain the methods of List data type in Python for the following operations with suitable code
snippets for each.
(i) Adding values to a list ii) Removing values from a list
(iii) Finding a value in a list iv) Sorting the values in a list
15. Explain the various string methods for the following operations with examples.
(i) Removing whitespace characters from the beginning, end or both sides of a string.
(ii) To right-justify, left-justify, and center a string.
MODULE 3
1. With code snippet, explain saving variables using the shelve module and PPrint Pformat() func-
tions.
2. Write a program that reads a string with five characters which starts with ‘a’ and ends with ‘z’.
Print search successful if pattern matches string.
3. Describe the difference between Python OS and os.path modules. Also, discuss the following
methods of os module
chdir() b) rmdir() c) walk() d) listdir() e) getcwd()
Explain the file Reading/Writing process with suitable Python Program.
4. How do we specify and handle absolute, relative paths?
5. Explain saving of variables using shelve module.
6. Demonstrate Multiline Strings and Multiline Comments with example
7. Explain useful String methods with example
8. Demonstrate Slicing and Indexing on a string
9. Describe the copy() and paste() method in pyperclip module
10. What are the three “mode” arguments that can be passed to the open() function?
MODULE 4
1. Explain the functions of Shutil Module with examples
2. Explain buttons in the debug control window
3. What is meant by compressing the files? Explain reading, extracting and creating ZIP files with code
snippet.
4. Demonstrate the copy, move, rename and delete functions of shutil module with Python code snip-
pet.
5. Define assertions. What does an assert statement in python consists of? Explain how assertions can
be used in traffic light simulation with Python code snippet.
6. With code snippet, explain reading, extracting and creating ZIP files.
7. Demonstrate how to rename and move the files and folders
8. Explain Permanently deleting the Files and Folders
9. what is the difference between the delete functions in the send2trash and shutil modules?
10. What is the difference between shutil.copy() and shutil.copytree()
11. Explain the use of Assertion in Traffic Light Simulation
12. Describe the different Logging levels.
MODULE 5
1. What is class,object,attributes. Explain copy.copy() with an example.
2. Demonstrate pure functions and modifiers with examples.
3. Use the datetime module to write a program that gets the current date and prints that day of the week.
4. Explain operator overloading and polymorphism with examples.
5. Illustrate the concepts of inheritance and class diagrams with examples.
6. Write a function called print time that takes a time object and print it in the form of hour : minute :
second.
7. What is a class? How to define a class in Python? How to instantiate a class and how the class
members are accessed?
8. Differentiate class variables and instance variables.
9. Write a python program that uses datetime module within a class,takes a birthday as input and prints
the age and the number of days,hours,minutes and seconds until the next birthday.
10. Write a program that as a class Point with attributes as X and Y co-ordinates.Create two objects of
this class and find the midpoint of both the points. Add a method reflex_x to class point,which re-
turns a new point. Which is the reflection of the point about the x-axis. Ex:point(5,10)→reflex_x re-
turns point(5,-10).
11. Write a program that has a class Person,inherit a class Student from Person which also has a class
MarksAttendance.Assume the attributes for Person class as :USN,Name,dob,gender.Attributes for
Student class as Class,branch,year,MA.Attributes for MarksAttendance:Marks,Attendance.
Create a student S=Student(“1AB16CS005”,”XYZ”,”18-1-90”,”M”,85,98) and display the details of
the student.
12. How the class can be instantiated in python?Write a python program to express instances as return
values to define a class RECTANGLE with members width,height,corner_x,corner_y and member
functions:to find centre,area and perimeter of a rectangle.
13. Explain init and str method with an example python program.
14. Define polymorphism. Demonstrate polymorphism with function to find histogram to count the
number of times each letter appears in a word and in a sentence.
15. What is a pure function? Write a python program to find duration of event if start and end time is
given by defining class TIME.