12th Chemistry Revision Exam 2024
12th Chemistry Revision Exam 2024
Global scope refers to variables defined at the top level of a program or module, making them accessible from any part of that program. Local scope refers to variables defined within a function or block, limiting their accessibility to that particular section. For example, a variable defined within a function is local and cannot be accessed outside, while a global variable can be accessed by any function within the program module .
A pure function is a function where the output value is determined only by its input values, without observable side effects. It always returns the same result given the same arguments, making it reliable and easy to test. On the other hand, an impure function may produce side effects besides returning a value, such as modifying a global variable or interacting with input/output operations. For example, a pure function might simply return the sum of two numbers, while an impure function might log data to a console or modify a database record .
The 'break' statement is used to exit a loop prematurely when a certain condition is met, effectively stopping further iterations of the loop. It is typically used when it's clear further execution is unnecessary or when searching for a condition is successful. The 'continue' statement, on the other hand, is used to skip the current iteration and proceed to the next iteration of the loop, often used for skipping over unwanted sections of data or results within loop operations .
A recursive function is a function that calls itself within its own definition. This feature allows the function to repeat its behavior a certain number of times or until a condition is met. Recursive functions are different from other functions due to this self-referential nature, which enables them to solve problems that exhibit recursive structure, such as computing factorials or traversing trees .
In Python, lists are mutable, meaning their contents can be changed (elements can be added, removed, or modified), which makes them suitable for collections of items that need to be modified. Tuples, on the other hand, are immutable, meaning once they are created, their contents cannot be changed. This immutability makes tuples useful for storing fixed collections of items, ensuring the data integrity of a dataset .
Nested tuples in Python refer to tuples that contain other tuples as elements. This type of nested structure is useful for representing multi-dimensional data and complex relational information, such as a matrix or a list of coordinate points. An example might involve using nested tuples to manage a seating chart for an event or storing pixel values for image processing tasks, where each tuple element represents different attributes or dimensions of the data .
Algorithms are characterized by their correctness, efficiency, and clarity. Correctness ensures that an algorithm accurately solves a problem for all inputs. Efficiency relates to how quickly and with what resources an algorithm solves a problem, typically assessed in terms of time and space complexity. Clarity ensures the algorithm is understandable and maintainable. These characteristics are essential because they determine how effectively and reliably an algorithm can be implemented and scaled in solving real-world problems .
The input() function in Python is used to capture user input from the console, allowing users to interact with a program by providing necessary data at runtime. The print() function is used to display output to the console, providing information, results, or feedback to the user. Together, these functions enable interaction between the user and the program, facilitating a dynamic exchange of information .
Sorting algorithms differ in their methodology for arranging data, thus varying in the number of swaps needed to achieve a sorted sequence. Bubble sort, for example, typically requires more swaps, as it repeatedly moves the largest unsorted element to its correct position, which involves multiple element swaps. On the other hand, selection sort generally requires fewer swaps because it selects the minimum element from the unsorted part each time and swaps it with the first unsorted element. The algorithm that minimizes swaps largely depends on the specific implementation and the initial configuration of the dataset .
Scope in programming refers to the context within which variables can be accessed or modified. It defines the visibility and lifetime of variables. A variable's scope determines if it is accessible outside the block where it is defined, which can be within a function, module, or class. This restricts unintended interference from other parts of the program and helps in managing memory efficiently by allowing variables to be discarded once they go out of scope .