- 博客(12)
- 收藏
- 关注
原创 CS 61A 2020 Fall Disc 06: Nonlocal, Mutability, Iterators 待补充
1.1 Write a function that takes in a number n and returns a one-argument function. The returned function takes in a function that is used to update n. It should return the updated n.def memory(n): """ >>> f = memory(10) >>
2021-10-10 22:08:25 865
原创 CS 61A 2020 Fall Lab 6: Nonlocal, Mutability
Q1: Make Adder IncreasingWrite a function which takes in an integeraand returns a one-argument function. This function should take in some valueband returna + bthe first time it is called, similar tomake_adder. The second time it is called, howev...
2021-10-06 23:17:06 847
原创 CS 61A 2020 Fall Project 1: The Game of Hog
"""CS 61A Presents The Game of Hog."""from dice import six_sided, four_sided, make_test_dicefrom ucb import main, trace, interactGOAL_SCORE = 100 # The goal of Hog is to score 100 points.FIRST_101_DIGITS_OF_PI = 314159265358979323846264338327950288.
2021-10-03 23:59:44 968
原创 CS 61A 2020 Fall Lab 5: Data Abstraction, Trees
Q1: CoupleImplement the functioncouple, which takes in two lists and returns a list that contains lists with i-th elements of two sequences coupled together. You can assume the lengths of two sequences are the same. Try using a list comprehension.d.
2021-10-03 22:52:04 1447
原创 CS 61A 2020 Fall Lab 4: Recursion, Tree Recursion, Python Lists
Q1: List IndexingFor each of the following lists, what is the list indexing expression that evaluates to7? For example, ifx = [7], then the answer would bex[0]. You can use the interpreter or Python Tutor to experiment with your answers. If the code ...
2021-10-03 22:09:36 1531 1
原创 CS 61A 2020 Fall Disc 03: Recursion
1.1 Write a function that takes two numbers m and n and returns their product.Assume m and n are positive integers. Use recursion, not mul or *!Hint: 5*3 = 5 + 5*2 = 5 + 5 + 5*1.For the base case, what is the simplest possible input for multiply?1
2021-09-26 23:43:53 830 1
原创 CS 61A 2020 Fall Disc 02: Higher-Order Functions, Self Reference
1.1 Write a function that takes in a function cond and a number n and prints numbers from 1 to n where calling cond on that number returns True.def keep_ints(cond, n):"""Print out all integers 1..i..n where cond(i) is true>>> def is_even(x):
2021-09-26 22:28:23 387
原创 CS 61A 2020 fall Disc 01: Environment Diagrams, Control
1.1 Alfonso will only wear a jacket outside if it is below 60 degrees or it is raining.Write a function that takes in the current temperature and a boolean value tellingif it is raining and returns True if Alfonso will wear a jacket and False otherwise
2021-09-26 11:27:55 472
原创 CS 61A 2020 fall HW02
Q1: Num eightsWrite a recursive functionnum_eightsthat takes a positive integerxand returns the number of times the digit 8 appears inx.Use recursion - the tests will fail if you use any assignment statements.def num_eights(x): """Returns ...
2021-09-25 23:05:02 1095
原创 CS 61A 2020 fall Lab 2: Higher-Order Functions, Lambda Expressions
Q1: WWPD: Lambda the Free>>> lambda x: x # A lambda expression with one parameter x<function <lambda> at ...>______>>> a = lambda x: x # Assigning the lambda function to the name a>>> a(5)5______>&g
2021-09-20 00:39:21 1959
原创 CS 61A 2020 fall Lab 1: Variables & Functions, Control
What Would Python Display? (Part 1)Q1: WWPD: ControlUse Ok to test your knowledge with the following "What Would Python Display?" questions:python3 ok -q control -uHint: Make sure yourwhileloop conditions eventually evaluate to a false value, o..
2021-09-17 00:21:32 1892 1
原创 CS 61A 2019 fall HW01
Homework 1: Variables & Functions, ControlQ1: Syllabus QuizQ2: A Plus Abs BFill in the blanks in the following function for addingato the absolute value ofb, without callingabs. You maynotmodify any of the provided code other than the two ...
2021-09-14 22:11:27 843 2
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人