1.
What is a subroutine? (2 MARKS)
2.
Differentiate pure and impure function (3 MARKS)
3.
Explain the necessity of computer in human life (3 MARKS)
4.
Explain with an example interface and implementation. (5 MARKS)
5.
Explain what is a parameter with type and parameter without the type (2 marks)
6.
The small sections of code that are used to perform a particular task is called
Correct Answer
A. Subroutines
Explanation
Subroutines are small sections of code that are used to perform a particular task. They are reusable and can be called multiple times within a program. Subroutines help in organizing code and making it more modular, as different tasks can be separated into different subroutines. This improves code readability, maintainability, and reusability. Therefore, the correct answer is Subroutines.
7.
Which of the following is a unit of code that is often defined within a greater code structure?
Correct Answer
B. Function
Explanation
A function is a unit of code that is often defined within a greater code structure. It is a reusable block of code that performs a specific task and can be called or invoked from other parts of the code. Functions help in organizing and modularizing code, making it easier to read, understand, and maintain. They allow for code reusability and promote the concept of DRY (Don't Repeat Yourself) programming.
8.
Which of the following is a distinct syntactic block?
Correct Answer
D. Definition
Explanation
A distinct syntactic block refers to a section of code that is enclosed within a specific structure and can be treated as a single unit. Subroutines, functions, and modules are all programming constructs that can contain multiple lines of code, but they are not considered distinct syntactic blocks. On the other hand, a definition, such as a variable or constant declaration, is a self-contained unit that can be easily identified and separated from the rest of the code, making it a distinct syntactic block.
9.
The variables in a function definition are called as
Correct Answer
C. Parameters
Explanation
The variables in a function definition are called parameters. Parameters are placeholders that allow us to pass values into a function when it is called. They define the input that a function expects and can be used within the function's body to perform operations or calculations. By using parameters, we can make our functions more flexible and reusable, as they can work with different values each time they are called.
10.
The values which are passed to a function definition are called
Correct Answer
A. Arguments
Explanation
When we pass values to a function, these values are referred to as arguments. Arguments are used to provide input to the function and can be of any data type. The function then performs operations or calculations using these arguments and may return a result. In this context, the term "arguments" is the correct answer as it accurately describes the values passed to a function.
11.
Which of the following are mandatory to write the type annotations in the function
definition?
Correct Answer
B. Parentheses
Explanation
Parentheses are mandatory to write the type annotations in the function definition. Type annotations are used in Python to specify the type of arguments and return values of a function. They are placed within parentheses after the function name and before the colon. This helps in providing clarity and ensuring type safety in the code.
12.
Which of the following defines what an object can do?
Correct Answer
C. Interface
Explanation
An interface defines what an object can do by specifying a set of methods that the object must implement. It acts as a contract that enforces certain behaviors and functionality for objects that implement it. By using interfaces, we can achieve abstraction and polymorphism in object-oriented programming, allowing different objects to be treated interchangeably based on their shared interface.
13.
Which of the following carries out the instructions defined in the interface?
Correct Answer
A. Implementation
Explanation
The implementation is responsible for carrying out the instructions defined in the interface. The interface defines the contract or blueprint for how the instructions should be implemented, and the implementation is the actual code that fulfills those requirements. It is the implementation that executes the instructions and performs the desired actions or operations.
14.
The functions which will give exact result when same arguments are passed are called
Correct Answer
D. Pure functions
Explanation
Pure functions are functions that always produce the same output for the same input, regardless of any external factors. They do not have any side effects and do not modify any variables outside their own scope. This makes them predictable and easier to test and debug. Impure functions, on the other hand, may produce different results for the same input due to their reliance on external factors or state. Partial functions and dynamic functions are not relevant to the concept of functions producing the exact result when the same arguments are passed.
15.
The functions which cause side effects to the arguments passed are called
Correct Answer
C. Impure function
Explanation
An impure function is a function that can modify or have side effects on the arguments passed to it. This means that when the function is called, it can change the values of the arguments, modify global variables, or perform any other actions that affect the state of the program. In contrast, pure functions do not have any side effects and only depend on their input parameters to produce a result. Therefore, the correct answer is impure function.