Due by 11:59pm on Tuesday, 10/18

Instructions

This homework is worth only 1 point (regular assignments are worth 2).

Download hw08.zip. This homework contains an AutoStyle assignment.

You must run python3 ok --submit and complete the AutoStyle assignment to receive full credit for this homework. The AutoStyle assignment will take about 1 hour and must be completed by yourself in a single sitting.

Submission: When you are done, submit with python3 ok --submit. You may submit more than once before the deadline; only the final submission will be scored. Check that you have successfully submitted your code on okpy.org. See Lab 0 for more instructions on submitting assignments.

Using OK: If you have any questions about using OK, please refer to this guide.

Readings: You might find the following references useful:

AutoStyle

The following problem will be used as part of the AutoStyle study which you can find more information about on Piazza.

Question 1: Deep Length

A list that contains one or more lists as elements is called a deep list. For example, [1, [2, 3], 4] is a deep list.

A deep list of integers is a list containing either integers or deep lists. Implement deep_len, which takes in a deep list of integers lst. It returns the number of integers that appear anywhere within lst.

Hint: you can check if something is a list by using the built-in type function. For example,

>>> type(3) == list
False
>>> type([1, 2, 3]) == list
True
def deep_len(lst):
    """Returns the deep length of the list.

    >>> deep_len([1, 2, 3])     # normal list
    3
    >>> x = [1, [2, 3], 4]      # deep list
    >>> deep_len(x)
    4
    >>> x = [[1, [1, 1]], 1, [1, 1]] # deep list
    >>> deep_len(x)
    6
    >>> x = []
    >>> for i in range(100):
    ...     x = [x] + [i]       # very deep list
    ...
    >>> deep_len(x)
    100
    """
    "*** YOUR CODE HERE ***"

Use OK to test your code:

python3 ok -q deep_len

Question 2: Run AutoStyle

Once you have passed all the tests, invoke AutoStyle by running the command:

python3 ok --style -q deep_len

AutoStyle will provide hints to help improve code style and composition. The process will take about 1 hour and must be completed in a single sitting.

When running AutoStyle, please don't place any print statements into your code. If you would like to test your code with print statements, try running it in a terminal on your computer.

If you run into any problems, please make a private post on Piazza tagged under the folder autostyle and include a screenshot of the error as well as a copy of your code.