KTU Python Programming - Theory Questions
Strings and Text Files
1. Explain how strings are stored in memory in Python. What are immutable objects?
2. Write a Python program to count the number of vowels in a text file.
3. Explain the difference between string slicing and substring search. Give examples.
4. What is data encryption? Explain any one encryption technique with a Python example.
5. How can you convert a number to a string in different number systems (binary, octal, hex)? Give examples.
6. List and explain any five string methods in Python with examples.
7. Write a program to find the frequency of each word in a given text file.
8. Case Study: Given a large text file, design a program to extract and display the top 10 most frequent
words. Explain your approach.
Design with Functions
1. Explain the role of functions as abstraction mechanisms. Illustrate with an example.
2. Design a program using top-down design for a simple online billing system. Describe your approach.
3. Write a recursive function to compute the nth Fibonacci number.
4. What is meant by a program's namespace? How is it managed in Python?
5. Explain with examples: local, global, and nonlocal variables.
6. Define a higher-order function. Write a Python program using map() to square a list of numbers.
7. What is lambda in Python? How is it used with filter() and reduce() functions?
Lists
1. Explain any five built-in list functions in Python with examples.
2. Write a Python program to sort a list of student names using bubble sort.
3. What are nested lists? Write a program to find the sum of each row in a 2D list (matrix).
4. Explain slicing in lists with examples.
5. Compare linear search and binary search in terms of performance and implementation.
6. Write a Python program using list comprehension to generate all even numbers between 1 and 100.
7. Case Study: You are given a list of student records (name, age, marks). Design a program to sort them
based on marks and display the top 5 performers.
KTU Python Programming - Theory Questions
Tuples, Sets, Dates and Times
1. Differentiate between lists and tuples. When would you prefer tuples over lists?
2. Write a program to perform union, intersection, and difference operations on sets.
3. Write a Python program to calculate the number of days between two dates using datetime module.
4. Give an example where tuples can be used as dictionary keys but lists cannot. Explain why.
5. Case Study: Design a student attendance management system using dates and sets.
Dictionaries
1. Write a Python program to read a text file and create a dictionary of word frequencies.
2. Explain reverse lookup in dictionaries with an example.
3. Differentiate between dictionary literals and dictionary constructors. Write code to demonstrate adding,
removing, and modifying dictionary entries.
Objects and Classes
1. Define a class in Python to represent a Book with attributes like title, author, and price. Write methods to
display details and apply a discount.
2. Differentiate between a class and an object with suitable examples.
3. What is the purpose of the __init__() method in Python classes? Explain with an example.
4. Write a Python program to model a Student class with instance variables name, roll_no, and marks.
Include appropriate methods.
5. Explain the terms accessor and mutator methods. Give code examples of each.
6. What is meant by encapsulation? How does Python support it using classes?
7. How are instance variables and class variables different in Python? Illustrate with code.
Data Modeling and Class Design
1. Model a class BankAccount with attributes like account number, account holder, and balance. Implement
methods to deposit and withdraw.
2. Case Study: You are designing a class-based system for a Library. Identify the objects, attributes, and
methods involved.
KTU Python Programming - Theory Questions
3. Write a program to model a Car class and a ServiceRecord class where each car has a list of service
records. Demonstrate composition.
4. Design a class for an online shopping item with methods to calculate discount and tax.
5. What are the advantages of designing programs using classes and objects?
Inheritance and Polymorphism
1. What is inheritance? How is it implemented in Python? Give an example.
2. Create a base class Employee and a derived class Manager. Add a method in Manager to calculate
bonus. Demonstrate polymorphism.
3. Write a Python program to show method overriding with inheritance.
4. Explain the super() function in Python with an example.
5. Differentiate between single and multiple inheritance with examples.
6. How is polymorphism achieved in Python? Illustrate using class hierarchy.
7. Case Study: Design a vehicle management system using a base class Vehicle and subclasses Car, Bike,
and Truck. Show method overriding.
Abstract Classes and Interfaces
1. What is an abstract class in Python? How do you implement one using the abc module?
2. Write a Python program using an abstract class Shape with an abstract method area(). Create subclasses
Circle and Rectangle.
3. Explain the difference between abstract classes and interfaces. How can interfaces be simulated in
Python?
4. Can an abstract class have constructors and implemented methods in Python? Justify with example.
5. What happens if a subclass does not override all abstract methods of its parent class?
Exception Handling
1. What is exception handling? Why is it important in object-oriented programming?
2. Write a program that handles a divide-by-zero error using a try-except block.
3. How can you handle multiple exceptions in Python? Give an example.
KTU Python Programming - Theory Questions
4. Write a program to take input from the user and raise a ValueError if the input is not an integer. Handle it
appropriately.
5. What is the difference between except, else, and finally blocks in Python exception handling? Explain with
an example.
6. Case Study: Design a student result program that handles exceptions like invalid marks entry and
division-by-zero when calculating averages.