Computer Science
Assertion. A function declaring a variable having the same name as a global variable, cannot use that global variable.
Reason. A local variable having the same name as a global variable hides the global variable in its function.
Answer
(a)
Both Assertion and Reason are true and Reason is the correct explanation of Assertion.
Explanation
Inside a function, you assign a value to a name which is already there in global scope, Python won't use the global scope variable because it is an assignment statement and assignment statement creates a variable by default in current environment. That means a local variable having the same name as a global variable hides the global variable in its function.
Related Questions
Assertion. A variable not declared inside a function can still be used inside the function if it is declared at a higher scope level.
Reason. Python resolves a name using LEGB rule where it checks in Local (L), Enclosing (E), Global (G) and Built-in scopes (B), in the given order.
Assertion. A parameter having a default value in the function header is known as a default parameter.
Reason. The default values for parameters are considered only if no value is provided for that parameter in the function call statement.
Assertion. If the arguments in a function call statement match the number and order of arguments as defined in the function definition, such arguments are called positional arguments.
Reason. During a function call, the argument list first contains default argument(s) followed positional argument(s).
A program having multiple functions is considered better designed than a program without any functions. Why ?