UNIT 03 – Programming Fundamentals
Exercise
Select the best answer for the following Multiple-Choice Questions (MCQs).
1. Main purpose of the programming paradigm is
a. Increase code length b. Complexity reduction
c. Eliminate bugs d. Improve hardware performance
2. programming paradigm emphasizes the use of functions without changing state.
a. Procedural b. Functional c. Object-oriented d. Structural
3. Object-Oriented Programming primarily revolves around of the following:
a. Data structures b. Functions c. Objects d. Variables
4. In Python data structure is used to store a collection of items:.
a. List b. Dictionary c. Tuple d. Set
5. A dictionary stores in Python.
a. Keys only b. Values only c. Key-value pairs d. Sequential data
6. An example of disk l/O
a. Storing a variable in memory b. Reading a file from the hard disk
c. Defining a function d. Looping through a llst
7. To write content to a file in Python méthod is used.
a. [Link]() b. [Link]() c. [Link]() d. [Link]()
8. A primary key in a database is_
a. A key that has a default value b. A unique identifier for records
c. A key for linking multiple databases d. A key used for temporary tables
9. A common database normalization goal is
a. Reducing redundancy b. Maximizing data size
c. Increasing the number of tables d. Storing duplicate records
10. _____ key is used to uniquely identify a record in a related table.
a. Primary b. Secondary c. Foreign d. Unique
11. To create a simple GUI in Python, library is used.
a. Pygame b. OS c. Sys d. math
12. A nested list in Python is referred as
a. A list containing another list b. A list of dictionaries
c. A dictionary of lists d. A set containing multiple lists
13. The purpose of unit testing in Python is
a. Test individual units of code b. Test the entire program
c. Debug the entire program d. Optimize the code for speed
14. The primary goal of debugging is
A Writing new code b. Fixing errors in the code
c. Increasing program speed d. Creating a graphical interface
15. Python function used to print debugging messages to the console
a. print() b. debug() c. trace() d. log()
16. Output of the following code will be:
my_d1ct = {"a" : [1, 2], "b" : [3, 4]}
print(my„dict[”a“][1})
a.1 b. 2 c. [1, 2] d. [J, 4]
17. The code will print "lnner" ______ times.
for i in range(3):
for j in range(2): print(“Inner")
a.2 b.3 c.5 d.6
Answer Key (MCQs)
1. b) Complexity reduction 2. b) Functional
3. c) Objects 4. a) List
5. c) Key–value pairs 6. b) Reading data from hard disk
7. a) [Link]() 8. b) A unique identifier for records
9. a) Reducing redundancy 10. c) Foreign key
11. a) Pygame 12. a) A list containing another list
13. a) Test individual units of code 14. b) Fixing errors in the code
15. a) print() 16. b) 2
17. d) 6
Give short answers to the following Short Response Questions (SRQs).
1: What is a programming language paradigm and why is it important for software
development?
Ans. A programming language paradigm is a particular style or approach used to design and
write programs. It provides a set of rules, concepts, and best practices for solving problems
using code. Examples include Functional Programming and Object-Oriented Programming.
Programming paradigms are important because they help programmers structure their code
efficiently, reduce complexity, improve readability, and make software easier to maintain and
modify.
2: How do you interpret the concept of complexity reduction in programming? How
does dividing code into modules help manage complexity?
Ans. Complexity reduction in programming means simplifying large and complicated
problems by breaking them into smaller and manageable parts. Dividing code into modules
or functions allows programmers to focus on one task at a time. This makes the program
easier to understand, debug, test, and update. Modular code also improves reusability and
reduces errors.
3: Compare Functional Programming and Object-Oriented Programming (OOP). Enlist
main differences in their approach to problem-solving.
Ans. Functional Programming focuses on solving problems using functions and avoids
changing data or state. It emphasizes immutability and mathematical functions. On the other
hand, Object-Oriented Programming is based on objects and classes that represent real-
world entities. OOP combines data and functions together, whereas Functional Programming
keeps them separate.
4: What is Disk I/O and why is it important for system performance?
Ans. Disk Input/Output (I/O) refers to the process of reading data from and writing data to
storage devices such as hard disks or SSDs. It is important for system performance because
programs rely on disk I/O to load applications, save files, and retrieve data. Efficient disk I/O
improves system speed and ensures smooth execution of tasks.
5: Describe the different modes in file handling in Python.
Ans. Python provides several file handling modes. The r mode is used to read files, w mode
is used to write data and overwrites existing content, a mode appends data to a file, and r+
mode allows both reading and writing. Selecting the correct mode is essential for proper file
operations.
6: What is the benefit of using the with keyword while working with files in Python?
Ans. The with keyword simplifies file handling by automatically closing the file after the block
of code is executed. It also ensures that the file is closed even if an error occurs during
execution. This helps prevent data loss and resource leakage, making file operations safer
and more reliable.
7: How can you create a simple GUI application using Pygame? Enlist the steps
involved.
Ans. To create a simple GUI application using Pygame, first import the pygame library and
initialize it. Then create a window using display.set_mode(). Handle user events such as
mouse clicks or key presses using an event loop. Finally, update the display continuously
until the application is closed.
8: Describe the use of a nested list in Python and how it can be used to represent a
matrix.
Ans. A nested list in Python is a list that contains other lists as its elements. It is commonly
used to represent a matrix where each inner list represents a row of the matrix. Nested lists
allow easy access to rows and columns using index values and are useful for mathematical
and data-processing tasks.
9: What is data normalization and why is it used in database management?
Ans. Data normalization is a database design technique used to organize data efficiently by
dividing it into multiple related tables. It reduces data redundancy and improves data integrity.
Normalization also makes databases easier to maintain and ensures consistency when
inserting, updating, or deleting records.
10: What is debugging and why is it important in software development?
Ans. Debugging is the process of identifying, analyzing, and fixing errors or bugs in a
program. It is important because errors can cause incorrect output or program failure.
Debugging helps ensure that software works correctly, improves program reliability, and
enhances overall software quality.
11: What seems to be the problem in:
sample_dict: = {"a" : 1, "b" : 2}
print(sample_dict["c"])
Ans Key "c" does not exist in the dictionary, causing a KeyError.
12. Final value of my_list after the following lines would be:
own_list = [1, 2, 3]
own_list.append(4, 5)
Ans. append() accepts only one argument → Error occurs
Non-Exercise Questions
1. What is a text file?
Ans. A text file stores data in human-readable form using characters. It can be opened and
read using simple text editors. Text files are commonly used to store information such as logs,
configuration data, and documents.
2. What is a binary file?
Ans. A binary file stores data in machine-readable binary format. It cannot be read directly
by humans. Binary files are used for images, videos, executable programs, and other non-
text data.
3. Explain the purpose of the read() function in Python.
Ans. The read() function is used to read the contents of a file. It can read the entire file or a
specified number of characters. It is commonly used when file data needs to be processed
or displayed.
4. What does the write() function do in Python file handling?
Ans. The write() function writes data to a file. If the file is opened in write mode, existing data
is replaced. It is used to store program output or user data in files.
5. Explain append mode in file handling.
Ans. Append mode (a) allows new data to be added at the end of an existing file. Previous
data remains unchanged. This mode is useful for maintaining logs or adding records without
losing existing data.
6. Why is error handling important in file operations?
Ans. Error handling prevents program crashes when problems occur, such as missing files
or permission issues. It ensures smooth execution and allows the program to respond
properly to errors.
7. What is a nested list in Python?
Ans. A nested list is a list that contains other lists as its elements. It allows storing data in a
structured form and is useful for representing tables and matrices.
8. What is a dictionary in Python?
Ans. A dictionary is a data structure that stores data in key-value pairs. It allows fast data
retrieval using unique keys and is commonly used to store related information.
9. Why must dictionary keys be unique?
Ans. Dictionary keys must be unique so that each value can be identified correctly. Duplicate
keys would overwrite existing data and cause confusion.
10. Why are lists used as dictionary values?
Ans. Lists are used as dictionary values to store multiple related items under one key. This
makes data organization more flexible and meaningful.
11. What is unit testing?
Ans. Unit testing is the process of testing individual functions or modules of a program to
ensure they work correctly. It helps detect errors early.
12. Explain dictionaries and their applications.
Dictionaries store data in key-value pairs. They allow fast access to data using keys and are
widely used for storing structured information such as student records or configuration
settings.
SRQs from Object-Oriented Programming (OOP)
1. What is Object-Oriented Programming (OOP)?
Ans. Object-Oriented Programming (OOP) is a programming paradigm that organizes a
program around objects and classes. Objects represent real-world entities and contain both
data (attributes) and functions (methods). OOP helps in building programs that are easier to
understand, maintain, and extend.
2. What is a class in Object-Oriented Programming?
Ans. A class is a blueprint or template used to create objects. It defines the data members
and methods that an object will have. Classes help in organizing code logically and allow the
creation of multiple objects with similar characteristics.
3. What is an object? Explain with reference to OOP.
Ans. An object is an instance of a class. It represents a real-world entity and contains actual
values for the attributes defined in the class. Objects use class methods to perform actions
and interact with other objects.
4. How does OOP help in reducing program complexity?
Ans. OOP reduces program complexity by dividing a program into objects, each responsible
for a specific task. This separation of responsibilities makes programs easier to understand,
debug, and maintain. Changes in one object usually do not affect other parts of the program.
5. Why is Object-Oriented Programming suitable for real-world problem solving?
Ans. OOP is suitable for real-world problem solving because it models programs using
objects that represent real-world entities. This makes the program structure more intuitive
and closer to real-life systems, improving clarity and maintainability.