Problem Set 5

Author

Lukas Hager

Published

May 1, 2024

This problem set must be submitted on Canvas by 11:59 PM PST on May 8, 2024.

Exercise 0

Please write a function that takes no arguments and returns a link to your solutions on GitHub.

Use the following shell:

def github() -> str:
    """
    Some docstrings.
    """

    return "https://github.com/<user>/<repo>/blob/main/<filename.py>"

Exercise 1

Please write a function called scrape_code that takes as its argument a lecture’s URL on the course website (the HTML format, so, for example, https://lukashager.netlify.app/econ-481/01_intro_to_python) and returns a string containing all the python code in the lecture formatted in such a way that we could save it as a python file and run it without syntax issues (note that if you try to do actually run the file, you’ll likely hit some syntax issues since there some that exist by construction in the presentations).

For example, if the only slide in Lecture 1 was this one, your function should return

"print('Peanut Butter' + 'Jelly')
str_list = ['I', 'love', 'UW']
' '.join(str_list)
month = 'April'
f'The month is {month}.'"

In reality, there are many other slides with code, so their code should also be included in the output string. Remember that it should be the case that if the code in the slides is syntactically correct, we could save down the output of this function and run it as a python file.

Warning

Remember that some slides use ipython’s magic commands (which all start with a % character); you should not include these lines in the python output, since that would break a python interpreter.

Use the following shell:

def scrape_code(url: str) -> str:
    """
    Some docstrings.
    """

    return None