In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of January 4th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #11 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
The sound of gunfire echoes through the hallway as Trinity sprints, her boots clattering on the floor. An Agent is hot on her heels.
"Operator, I need an exit! Find me a booth, Tank, NOW!" she shouts.
Tank's voice crackles back.
"I'm trying, Trinity, but most of the connections are offline.
Something’s wrong... booths are disappearing from the matrix!"
Suddenly, Neo's voice interrupts. "Tank, I'm going in. We need to confirm that these booths actually exist
before sending Trinity in. Someone is introducing these bugs on purpose."
Write a function find_exit(connections, check_booth, seed) that given a dictionary connections
, randomly deletes some booths and checks whether a given booth check_booth
still exists. In case the booth exists, the respective instructions should be returned. In case the booth has been deleted, an alert message should be returned instead: "Compromised booth! Aborting connection."
.
Consider the following:
seed
as an argument, so that the booths that get deleted might change with different seeds. You should use the input seed
to initialize the random number generator from module random
.random
module to implement this behaviour, using the random()
function (that generates a floating-point number in the range 0.0 <= X < 1.0
) and check if the generated number is smaller than 0.3 to see if it gets deleted (this check should be done in increasing order of the booth).connections
in your code to test:
connections = { "B1": "Go to the red door in the hallway and turn left.", "B2": "Head over to the back alley and find the hidden key.", "B3": "Find the elevator and press the secret button.", "B4": "Turn left at the second street and look for the green sign.", "B5": "Follow the alley until you see a blue dumpster, then turn right.", "B6": "Look for a door with a glowing symbol and open it.", "B7": "Enter the subway station, go down the stairs, and find the secret passage.", "B8": "Turn around and go through the abandoned building entrance.", "B9": "Find the underground tunnel entrance near the library.", "B1O": "Go straight ahead, take the first right, and find the hidden hatch." }For instance, using the above dictionary
connections
and a seed = 42
, only the following booths will remain: ['B1', 'B5', 'B6', 'B7', 'B9']This means that:
print(find_exit(connections, "B1", 42))
returns "Go to the red door in the hallway and turn left."
print(find_exit(connections, "B4", 42))
returns "Compromised booth! Aborting connection."
The following limits are guaranteed in all the test cases that will be given to your program:
connections |
The available connections to booths as shown above | |
-1000 ≤ seed ≤ 1000 |
The seed to randomly generate missing booths | |
check_booth \( \in \{B_1, \cdots, B_{1O}\} \) |
The booths to check in the dictionary |
Example Function Calls | Example Output |
print(find_exit(connections, "B1", 42)) print(find_exit(connections, "B4", 42)) print(find_exit(connections, "B9", 123)) |
Go to the red door in the hallway and turn left. Compromised booth! Aborting connection. Find the underground tunnel entrance near the library. |