Q) An algorithm has been developed to compute the sum of all the elements in a list of integers. Which of the following programming structures must be added to the existing algorithm so that the new algorithm computes the sum of only the even integers in the list?
options:
- Iteration
- Searching
- Selection
- Sequencing
Answer: 3 Selection
Selection Structure uses to make a decision or comparison and then, based on the result of that decision or comparison, to select one of two paths. The condition must result in either a true (yes) or false (no) answer. If the condition is true, the program performs one set of tasks.
Selections enable including more than one route in a program. Many solutions require multiple choices or decisions, and these choices result in various possible routes which the program can take. These routes signify the outcome of making a choice. Without selection it would not be possible to contain diverse routes in programs, and the solutions we come up with would not be realistic. You can read more about selection in programming here.
Read List, Set, Tuple, and Dictionary Data Structures in Python