Lecture 4 - Loops over Strings, Guess-and-Check, Binary Flashcards
1
Q
What is exhaustive enumeration?
A
2
Q
Why would I want to use a boolean flag in when iterating over a for loop?
A
To check if a certain condition has happened during the execution of the for loop. See example below where I want to know whether the secret number has been found or not during the loop.
secret = 4 secret_found = False for i in range(1,11): if secret == i: secret_found = True break if not secret_found: print('I did not find the secret') else: print(f'The secret value is {secret}')
3
Q
What is one limitation from using exahustive enumeration to solve a problem computationally?
A
Exhaustive enumeration only produces a solution if this solution is included in the search space defined.