You are on page 1of 6

Python Sample Question Bank

Module-1 Introduction to Python Programming


1. Explain different data types in python and demonstrate each with example. 5marks
2. Explain different operators provided by python. 6 marks
3. List the precedence of operators in python 5marks
4. Demonstrate operations of bitwise operators in python. 5 marks
5. Demonstrate float(),chr(), complex() str(), type() functions with example for each
(Explain type conversions in python and demonstrate with examples) 5 marks
6. Explain decision control flow(if,if-else,if-elif-else) statements and demonstrate each
with examples 6 marks
7. Differentiate break and continue statement with an example 5 marks
8. Explain loop control statements in python and demonstrate with examples for each.
6 marks
9. Demonstrate abs(),min(), max(), divmod(),pow() and len() functions with examples
6 marks
10. Demonstrate with an example the creation of string in python and usage of + , * and
comparison operators on it 5 marks
11. Explain with examples
i)indexing characters of a string,
ii)string slicing
iii) traversing through the characters of string iv)String joining and splitting
8 marks
12. Explain any 5 methods of string class with examples for each. 6 marks
13. What are functions? Demonstrate with an example program how functions are defined
and invoked in python? 6 marks
Sample Programming questions:
14. Write a python program to define a function to find the factorial of a number. Input
the number from user and invoke the function 5 marks
15. Write a python program to find whether the given number is prime or not, display
suitable message. 5 marks
16. Write a python program to count the number of vowels in a given string. 5 marks
17. Write a python program to find the sum of all the digits in an integer, input the integer
from user.
18. Write a python program to generate the following pattern for ‘n’ rows: (example n=4)
1
1 2
1 2 3
1 2 3 4
19. You need to empty out the rectangular swimming pool which is 12 meters long,
7 meters wide and 2 meter depth. You have a pump which can move 17 cubic
Meters of water in an hour. Write a program to find how long it will take to empty
Your pool? (Volume = l * w * h, and flow = volume/time
Develop a program that reads the date in the format (dd/mm/yyyy) and replaces the ‘/’
with a ‘-’ and displays the date in (dd-mm-yyyy) format
20. Write a Program That Accepts a Sentence and Calculate the Number of Digits,
Uppercase and Lowercase Letters

Module-2 Object-Oriented Programming

1. Write the syntax for creating a class and objects. Demonstrate the same with a
sample program
2. What are __init__ methods in python? Demonstrate with an example program.
3. What is inheritance explain with an example? What are the different types of
inheritance supported in python?
4. Explain the advantages of inheritance. Demonstrate Single inheritance with an
example.
5. Demonstrate multiple and multilevel inheritance with examples for each
6. Demonstrate the concept of polymorphism with an example
7. Explain abstraction and encapsulation with an example
8. Explain polymorphism with an example
9. Explain how operators are overloaded using magic methods. List the magic
methods used to overload the operators.
10. Differentiate between method overloading and method overriding with
example
11. Explain method overriding and super key words with suitable example.
Sample Programming questions:

12. Create a class called Book with data attributes title, author
and publication and include following methods: __init___ function to initialize all the details
of the book, printdetails() to print all the details of the book
13. Develop a program to check whether three points are collinear or not. Create a
class having x and y coordinates as attributes and a method taking point
objects as parameters and prints appropriate message.
14. Create a class named quadratic, where a, b, c are data attributes and the
methods are: __init__() to initialize the data attributes and roots() to compute
the quadratic equation
15. Create a class called Circle having radius as attribute, and __init__
constructor, area(), perimeter() as methods to find the area and perimeter of a
Circle object.
16. Develop a program with a base class Person having name and age as
attributes, a init constructor and display method to display the attributes.
Derive another class Student with attributes USN and percentage as attributes,
init and display methods. Create an object of student class and initialize and
display all attributes
17. Create two base classes named clock having hh,mm ,ss as attributes and
calendar having dd,mm,yy as attributes. Based on these two classes derive a
class calendarclock, which inherits from both the classes which displays
month details, date and time using the methods of the base classes. Create an
object and invoke appropriate methods.
18. Develop a class called complex having r and im as real and imaginary values.
Overload +, - , * operators to perform addition, subtraction and multiplication
of two complex numbers.
19. Create a class called Bank having name, adds, acno, and balance as attributes.
Include following methods: init constructor, withdrawl(), deposit(),
balenquiry(). Create an object and execute the methods based on user’s choice.
20. Write a program to create class Distance, having feet and inches as attributes.
Overload + operator to add two Distance objects, and > operator to compare
two distance objects.

Module-3 Arrays and Linked Structures


1. Explain contiguous memory allocation w.r.t arrays 4 marks
2. With a Python program demonstrate the operations of inserting an element and
deleting an element with an algorithm for each. 6 marks
3. List different methods used on array class 6 mark
4. Explain the algorithm of binary search with an example 5 marks
5. Explain the algorithm of bubble sort with an example 5 marks
6. Explain the algorithm of insertion sort with an example 5 marks
7. Explain the algorithm of selection sort with an example 5 marks
8. Explain with a program to create a singly linked structure. 6 marks
Sample Programming questions:
9. Write a python program to count the number of occurrence of a key element in
given array without using built in method.
Ex:10,20,30,10,50,10 key=10 must return count=2 5 marks
10. Write a python program to implement binary search on an array. 5 marks
11. Write a python program to implement insertion sort algorithm on an array. 5 mark
12. Write a python program to implement selection sort algorithm on an array. 5 mks
13. Write a python program to implement bubble sort algorithm on an array. 5 marks
14. Write a python program to find the sum of odd and even numbers in a given array
15. Develop python code for
i) inserting a node to a singly linked structure.
ii)traversing through linked structure
iii)delete a node . Create a linked structure of 5 nodes and print data values of all
the nodes. 10 marks

Module-4 Lists,Dictionaries,Sets and Tuples

1. What are Lists? Explain with examples the different ways to create a list. 4 marks
2. Why lists are called Mutable. Discuss the following List operations and functions
with examples:
i. Accessing, Traversing and Slicing the List Elements 5 marks
ii. + (concatenation) and * (Repetition) 2 marks
iii. Append, extend, sort, remove and delete 6marks
iv. len , sum, min and max 4 marks
v. split and join 2marks

3. What is list in Python? Demonstrate use of any three methods of list. 6 marks
4. Differentiate between the following:
1. pop() and remove() methods of list. 2marks
2. Del statement and pop() method of list. 2marks
3. append() and insert() methods of list. 2marks
5. Demonstrate the use of range function with examples 3marks
6. Demonstrate with example to access all the elements of a list using index and using
item of the list 4 marks
7. With example illustrate how the list can be passed as arguments to a function?
5 marks
8. Write a short note on Dictionary in python. 5 marks
9. Demonstrate the following with an example for each
i)Creation of dictionary
ii) Accessing elements of the dictionary
iii) Modifying key:value pairs 6 marks
10. Explain len(), all(), any() sorted() built in functions on dictionary 4 marks
11. Demonstrate pop(),popitem(), fromkeys(), get(), setdefault() and update() methods
with example for each. 6 marks
12. Demonstrate the following methods on dictionary with examples.
i)values() ii)keys() iii)items() 6 marks
13. Write a short note on tuples and sets 6 marks
14. Differentiate between lists and tuples 5marks
15. Explain any 5 methods on sets with an example for each 5marks
16. Compare list, tuple, sets and Dictionaries 8 marks

Programming questions:

17. Write a sort the list without using method. 6marks

18. Write a Python program to sum all the items in a list without using sum(). 4 marks
19. Write a Python program to get the largest and smallest number from a list without
using methods. 5 marks
20. Develop a Python Program to separate the given list elements into a list of odd and
even numbers. 5 marks
21. Write a program to implement binary search algorithm on a list. 6marks
22. Write a Python program to count the number of strings where the string length is 2 or
more and the first and last character are same from a given list of strings. Sample List:
['abc', 'xyz', 'aba', '1221'] Expected Result: 2 ---- 6 marks
23. Write a Python program to get the frequency (occurrence count) of the elements in a
list. -5 marks
24. Write a Python program to print the following from the 10 integer inputs entered by
the user stored in a list : -----8 marks
i. Total number of positive numbers
ii. Total number of negative numbers
iii. Total number of odd numbers
iv. Total number of even numbers
v. Total number of 0s.
25. Construct a dictionary that contains usernames as the keys and passwords as the
associated values. Make up the data for five dictionary entries. ----6marks
26. Write a Program to Dynamically Build a List from user inputs and demonstrate list
slicing with example.---6 marks
27. Write a Python Program That Accepts a Sentence as Input and Removes All
Duplicate Words. Print the Sorted Words. -6marks
28. Write a program to check whether an item exists within a tuple. If the item is present
print the index of the item else print a message “sorry not found”- 6 marks
29. Write a python program to separate alphabets,digits into two separate lists.
Example: s=”hello123” L1=[‘h’,’e’,’l’,’l’,’o’] L2=[1,2,3]. -6 marks
30. Write a python program that takes a range of input and creates a dictionary where in
key includes the number in the range and 2nd element as the square of that number.
example: input 4 and 6 o/p: dict=[4:16, 5:25, 6:36]—8 marks

Module -5 Files and Regular Expressions


Files:
1. Define file and explain the different types of files.
2. Explain the different file mode operations with examples
3. Describe with an example how to read and write to a text file.
4. Explain with an example how to read and write a binary file.
5. Illustrate with an example how to read and write a csv file.
6. Describe all the methods available in the os module
7. Write Python Program to Read and Print Each Line in ". txt" file.
8. Write Python Program to Count the Occurrences of Each Word and Also Count the
Number of Words in a “quotes.txt” File.

9. Write Python Program to Find the Longest Word in a File. Get the File Name from User.
10. Write Python program to read and display rows in "employees.csv" CSV file
that start with employee name "Jerry".
11. Write Python program to write the data given below to a CSV file.
Name,USN, percentage
ABC,1DS18XX001, 67
XYZ,1DS18XX002,75
PQR,1DS18XX003,82

Regular Expressions:
1. Define regular expression and list out all the advantages of the regular expression.
2. Describe any ten metacharacters with examples.
3. Write a regular expression which matches strings which starts with a sequence of
digits—at least one digit—followed by a blank and after these arbitrary characters.
4. Briefly explain the importance of the raw string notation.
5. Write a Python program to remove all leading zeros' from an IP address
6. Write a Python program to extract year, month and date from an url.

You might also like