Using the subjects dictionary, write a for loop that loops across the dictionary and collects all
subject numbers (ex. 'S2') where the dictionary value is True.
Imagine, for example, the dictionary indicates whether processing is complete, and we wanted to
get a list of the subjects where processing is complete.
To answer this question, use a for loop across the subjects dictionary. You then need to get the
associated value in each iteration and check if it is True. If it is False, you can use continue to
skip ahead to the next iteration. Otherwise, append the subject number (ex 'S2') to a list called
finished.
This dictionary provided for you
subjects = {
'S1' : True,
'S2' : True,
'S3' : False,
'S4' : False,
}
Q2 - Creating an Encoder
Write a code block to encode strings into a secret message.
Your code will presume a number, stored in key, and a message to encode, stored as a string
variable called message. Don't define these variables in your code - they will be defined when
you run the tests.
To do so:
● Initialize a variable called encoded as an empty string
● Use a for loop to loop across all characters of a string variable message
○ Inside the loop, convert the character to another character:
■ Get the unicode code point for the character (using ord)
■ Add the value of key to that code point (which should be an int)
■ Convert this new int back to a character (using chr).
○ Also inside the loop, add this converted char to the string encoded
Note: You should not define key or message in your answer. Those are defined in the cell below
where your code is executed (where you see %run)