Post

Cs61a Notes

Cs61a Notes

$intro$

我的代码

所有代码都会上传至我的$github$仓库

如何使用$ok$工具

1
python3 ok -q a_plus_abs_b --local

使用local命令来避免邮箱认证

完成情况

nameStatement
lab00Solved
hw00Solved
lab01Solved
hw01Solved
hogSolved
hw02Solved
lab02Solved
lab03Solved
hw03Solved

$Notes$

$hw$

hw02

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def make_repeater(f, n):
    """Returns the function that computes the nth application of f.

    >>> add_three = make_repeater(increment, 3)
    >>> add_three(5)
    8
    >>> make_repeater(triple, 5)(1) # 3 * (3 * (3 * (3 * (3 * 1))))
    243
    >>> make_repeater(square, 2)(5) # square(square(5))
    625
    >>> make_repeater(square, 3)(5) # square(square(square(5)))
    390625
    """
    "*** YOUR CODE HERE ***"
    if n==1:
        return f
    else:
        return lambda x: f(make_repeater(f,n-1)(x))

hw03

$Project$

Hog

唯一值得拿出来一说的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def make_averaged(original_function, times_called=1000):
    """Return a function that returns the average value of ORIGINAL_FUNCTION
    called TIMES_CALLED times.

    To implement this function, you will have to use *args syntax.

    >>> dice = make_test_dice(4, 2, 5, 1)
    >>> averaged_dice = make_averaged(roll_dice, 40)
    >>> averaged_dice(1, dice)  # The avg of 10 4's, 10 2's, 10 5's, and 10 1's
    3.0
    """
    # BEGIN PROBLEM 8
    "*** YOUR CODE HERE ***"
    def cal(*args):
        sum=0
        for i in range(times_called):
            sum+=original_function(*args)
        return sum/times_called
    return cal
    # END PROBLEM 8

可以学到多参数的写法

别的内容只要根据题目和代码中的描述来写,前面都学过的,只要认真仔细读懂具体每个函数是干什么的就行

因为函数说明没读仔细卡了一个晚上…不要学我

This post is licensed under CC BY 4.0 by the author.