<jupyter_start><jupyter_text>SLU 17 - Exam Prep I Batch 2 - Wave 1 Python Exam This is the Python exam from batch 2 - wave 1. Exam Duration: 2h<jupyter_code>from operator import itemgetter
#used for evaluation
import utils<jupyter_output><empty_output><jupyter_text>Question 1If you took a look at the dataset, you may have noticed that some of the numeric values are "polluted" with characters.In this task you'll have to write a function, `clean_percentage`, that should do the following:- Receive as argument a list of dictionaries; - Each of the dictionaries keeps the % of female students in higher education per area, for a specific year;- Remove all the characters and spaces from the numeric values;- Return the cleaned data;Hint: mind the naughty (R)'s :)<jupyter_code>def clean_percentage(data):
    # YOUR CODE HERE
    raise NotImplementedError()
utils.b2w1_exerc_1_grading(clean_percentage)
print("Answer is correct. Good Job.")<jupyter_output><empty_output><jupyter_text>Question 2In this task, we want to clean the names of the education areas, so they are all lower case and without white spaces.For instance, Social Sciences, Management and Law should become social_sciences_management_and_law.So you'll have to write two functions.The first function, `clean_header_string`, should do the following:- Receive a string as input;- Remove all the commas from the string;- Replace the white spaces in the string with underscores;- Convert the string to lower case;- Return the transformed string;The second function, `clean_header`, should do the following:- Receive as input, a list of dictionaries, similar to the one in the last question;- Use the first function to transform the education area names;- Return the transformed data;<jupyter_code>def clean_header_string(string):
    # YOUR CODE HERE
    raise NotImplementedError()

def clean_header(d):
    # YOUR CODE HERE
    raise NotImplementedError()
utils.b2w1_exerc_2_grading(clean_header_string, clean_header)
print("Answer is correct. Good Job.")<jupyter_output><empty_output><jupyter_text>Question 3In this task, we want to convert our data to the right data types.For this you'll have to write two functions.The first function, `commas`, should do the following:- Receive as input a list of dictionaries, similar to the previous questions;- Replace the commas with dots in the numeric values;- Return the transformed data;The second function `data_types` should do the following:- Receive as input a list of dictionaries (specifically the one returned by the first function);- Convert the year values to integer;- Convert the % of female students values to float;- Return the transformed data;<jupyter_code>def commas(d):
    # YOUR CODE HERE
    raise NotImplementedError()


def data_types(d):
    # YOUR CODE HERE
    raise NotImplementedError()
utils.b2w1_exerc_3_grading(commas, data_types)
print("Answer is correct. Good Job.")<jupyter_output><empty_output><jupyter_text>Question 4In this task, we want to focus on data about a specific education area.So you'll have to write a function, `education_years`  that should do the following:- Receive as input a list of dictionaries (similar to the ones of the previous questions), and an education area (string);- Return a list of tuples where the first value of the tuple is the year and the second value is the % of females in the given education area;In this task you're required to use the following:- `map` function;- `lambda` function;<jupyter_code>def education_years(data, education_area):
    # YOUR CODE HERE
    raise NotImplementedError()
utils.b2w1_exerc_4_grading(education_years)
print("Answer is correct. Good Job.")<jupyter_output><empty_output><jupyter_text>Question 5In this task, for a certain education area, we want to understand what were the years where more females were enrolled in higher education.So you'll have to write a function named `female_enrolled` that should do the following:- Receive as input a list of tuples with year and % of females (like the output of last task) and a threshold;- Filter **out** all the tuples that correspond to a % of females strictly below the threshold;- Sort the remaining tuples from higher to lower % of females;- Return the resulting list of tuples;In this task you're required to use the following:- `sorted` functionHint: `itemgetter` may be handy<jupyter_code>def female_enrolled(data, threshold):
    # YOUR CODE HERE
    raise NotImplementedError()
utils.b2w1_exerc_5_grading(female_enrolled, 58.1)
print("Answer is correct. Good Job.")<jupyter_output><empty_output><jupyter_text>Question 6In this task we'll create a class to play the lottery!First, get to know the `raffle_key`. The `raffle_key` is a dictionary, associating ticket numbers with prizes. All the numbers that are not in the raffle_key won't get any prize.<jupyter_code>raffle_key = {1:"10 euros", 5:"100 euros", 9:"40 euros"}<jupyter_output><empty_output><jupyter_text>Step 1:- Create a `Lottery` class that takes one constructor parameter called `raffle_key`;- In the `Lottery` class create a method named _get_lucky_ that receives the lucky_number as parameter;    and returns the strings "{X} euros" or "Better luck next time!", depending on the presence of the lucky number in the raffle key;- In our example above, our lucky number 9 corresponds to the response string "40 euros"    if in some case we get a lucky number that doesn't exist in the raffle key, we should print out "Better luck next time!"; Step 2:- Instantiate the `Lottery` class with name `simple_lottery` and with the given raffle key;- Call the method `get_lucky` with the given lucky number and print out the result;In this task you're required to use the following:- `try/except` statements;<jupyter_code>class Lottery():
# YOUR CODE HERE
raise NotImplementedError()
utils.b2w1_exerc_6_grading(Lottery, simple_lottery, raffle_key)
print("Answer is correct. Good Job.")<jupyter_output><empty_output><jupyter_text>Last but not least, submit your work! To submit your work, fill your slack ID in the `slack_id` variable (as a string).Example: `slack_id = "x-men"`Help: if you forgot your slack ID, [read this](https://moshfeu.medium.com/how-to-find-my-member-id-in-slack-workspace-d4bba942e38c).<jupyter_code># Submit your work!

#slack_id = 

# YOUR CODE HERE
raise NotImplementedError()
from submit import submit
assert isinstance(slack_id, str)

slu = 17_2
submit(slack_id, slu)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07220328478462969, 'fraction_numerical': 0.008986674930275797, 'mean_word_length': 5.442115768463074, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '127101', 'license': 'MIT', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1813, 'n_words': 823, 'path': 'Week 10/SLU17_2 - Exam Prep I/Exercise notebook.ipynb', 'repo_name': 'LDSSA/ds-prep-course-2021', 'size': '6454'}