Chapter No: 03
Short Question/Answer
1. Elaborate programming language paradigm and why is it
important for software development?
Answer: A programming language paradigm is a fundamental style of
computer programming, providing a way to structure and organize
code.
It is important because it dictates how a developer approaches problem-
solving, manages complexity, and structures software. Different paradigms
offer different tools and principles (e.g., objects, functions, logic) that are
better suited for specific types of problems or project requirements, thus
influencing code clarity, efficiency, and maintainability.
2. How do you interpret the concept of complexity reduction in
programming? How does dividing code into modules help manage
complexity?
Answer: Complexity reduction in programming refers to the practice
of breaking down a large, intricate problem or system into smaller,
more manageable parts.
Dividing code into modules helps manage complexity by:
Encapsulation: Hiding internal implementation details and exposing
only necessary interfaces.
Abstraction: Focusing on what a module does rather than how it does
it.
Reusability: Allowing modules to be used in different parts of a
program or in other projects.
Maintainability: Making it easier to debug, update, or replace
individual modules without affecting the entire system.
3. Compare Functional Programming and Object-Oriented
Programming (OOP) paradigms. Enlist main differences in their
approach to problem-solving.
Answer: Functional Programming (FP) and Object-Oriented
Programming (OOP) are two major programming paradigms with
distinct approaches.
Main differences:
Core Concept: OOP revolves around 'objects' (data and behavior
combined), while FP revolves around 'pure functions' (computation as
the evaluation of mathematical functions).
State Management: OOP often uses mutable state within objects,
whereas FP emphasizes immutability and avoids shared state.
Problem-Solving Approach: OOP models real-world entities and
their interactions, focusing on nouns (objects). FP models computation
as a series of function calls, focusing on verbs (actions/functions).
Side Effects: FP aims to eliminate side effects, making code easier to
test and reason about, while OOP manages side effects within object
methods.
4. What is Disk I/O and why is it important for system performance?
Answer: Disk I/O (Input/Output) refers to the process of reading data
from or writing data to a physical storage device, such as a hard
disk drive (HDD) or solid-state drive (SSD).
It is important for system performance because:
Speed Bottleneck: Disk I/O is typically much slower than CPU and
RAM operations.
Impact on Applications: Applications that perform frequent disk
operations (e.g., databases, file servers, large data processing) can
become I/O bound, meaning their overall speed is limited by the disk's
speed rather than the CPU's processing power. Optimizing disk I/O is
crucial for responsive system performance.
5. Describe the difference modes in file handling in Python.
Answer: Python supports several modes for opening files, which
determine how the file can be accessed.
Common modes include:
'r' (Read): Opens a file for reading only (default mode).
'w' (Write): Opens a file for writing. Creates a new file if it does not
exist or truncates (empties) the file if it exists.
'a' (Append): Opens a file for writing. Data is added to the end of the
file. Creates a new file if it does not exist.
'b' (Binary): Used in conjunction with other modes (e.g., 'rb', 'wb') to
handle binary data like images or executables.
't' (Text): Used in conjunction with other modes (e.g., 'rt', 'wt') to
handle text data (default mode).
'+' (Update): Used with other modes (e.g., 'r+', 'w+') to open a file for
both reading and writing.
6. What is the benefit of using the 'with' keyword while working with
files in Python?
Answer: The primary benefit of using the 'with' keyword in Python
file handling is that it ensures the file is automatically closed after
the block of code is executed, even if errors occur.
This prevents resource leaks (leaving file handles open), which improves
program reliability and simplifies code by removing the need for explicit
try...finally blocks or calling [Link]().
7. How can you create a simple GUI application using Pygame? Enlist
the steps involved.
Answer: Pygame is primarily a library for game development, but it
can be used for simple GUIs.
General steps involved:
1. Initialize Pygame: Call [Link]().
2. Set up the display: Create a screen surface using
[Link].set_mode().
3. Create a game loop: Use a while loop that runs continuously until the
user quits.
4. Handle events: Inside the loop, check for user input/events (e.g.,
[Link], mouse clicks) using [Link]().
5. Draw elements: Use Pygame drawing functions or render text/images
onto the screen surface.
6. Update the display: Call [Link]() or
[Link]() to show the drawn elements to the user.
7. Control frame rate: Use [Link]() to manage the speed of
the loop.
8. Describe the use of a nested list in Python and how can it be used
to represent a matrix?
Answer: A nested list in Python is a list that contains other lists as its
elements.
It can be used to represent a matrix (a 2D grid of data) where the outer list
represents the collection of rows, and each inner list represents a single row
of the matrix. For example, matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
represents a
3×33 cross 3
3×3
matrix. Elements can be accessed using double indexing, such as matrix[0]
[1] to get the element in the first row and second column (value 2).
9. What is data normalization and why is it used in database
management?
Answer: Data normalization is the process of organizing the columns
(attributes) and tables (relations) of a relational database to
minimize data redundancy (duplication) and ensure data integrity.
It is used in database management to:
Reduce Redundancy: Avoid storing the same data in multiple places,
saving storage space.
Improve Data Integrity: Ensure that data is consistent across the
database.
Prevent Anomalies: Avoid insertion, update, and deletion anomalies
that can occur with redundant data.
Enhance Maintainability: Make the database structure cleaner and
easier to manage and modify.
10. What is debugging and why is it important in
software development?
Answer: Debugging is the systematic process of identifying,
analyzing, and removing errors (bugs) or defects from a computer
program.
It is important in software development because:
Ensures Correctness: It verifies that the software behaves as
intended and meets requirements.
Improves Quality: It leads to more reliable, stable, and robust
software.
Enhances User Experience: A bug-free application provides a better
user experience and builds trust.
Saves Time and Cost: Finding and fixing bugs early in the
development lifecycle is much cheaper and faster than fixing them
after deployment
11. What seems to be the problem in:
Python
1 Sample_dict={"a": 1, "b": 2}
2 print(sample_dict["c"])
Step 1: Identify the error
The error is caused by trying to access a non-existent key 'c' in the
dictionary Sample_dict. Python dictionaries raise a KeyError when a key
is not found.
Answer:
KeyError: 'c' because the key 'c' does not exist in the
dictionary Sample_dict.
12. Final value of my_list after the following lines
would be:
Python
1 own_list =[1,2,3]
2 own_list.append(4,5)
Step 1: Analyze the append method
The [Link]() method in Python takes exactly one argument and
adds it as a single element to the end of the list. The second line
attempts to pass two arguments (4, 5) to append.
Step 2: Determine the outcome
Because append() is called with two arguments instead of one, the code
will raise a TypeError.
Answer:
TypeError: [Link]() takes exactly one argument (2 given)