CS61A Project2 Cats

Overview 使用如下命令对每个 question 检查正确性: python3 ok -q [question number] -i 使用 ok 系统允许的 debug 打印: print("DEBUG:", x) 运行 cats GUI 系统: python3 cats_gui.py Problem 1 实现 pick 函数,其中函数接受的参数: paragraphs: 表示 paragraphs 的字符串 list select: 一个对字符串的判断函数,return True or False k: 第 k 个满足 select 的 paragraphs 返回 paragraphs 中第 k 个满足 select 的字符串,没有满足的返回空字符串。 def pick(paragraphs, select, k): """Return the Kth paragraph from PARAGRAPHS for which the SELECT returns True. If there are fewer than K such paragraphs, return an empty string....

2024-09-29 · 4 min

SICP_Chapter1 Building Abstractions with Functions

1.2 Elements of Programming 1.2.6 The Non-Pure Print Function >>> print(print(1), print(2)) 1 2 None None 注意 print(1)和 print(2)的返回值是 None。 1.4 Designning Functions 1.4.1 Documentation docstring。在函数名后在``````中描述函数信息。第一行用来描述函数,接着空一行,接着可以描述参数等。 help(pressure)可以查看函数帮助信息。 >>> def pressure(v, t, n): """Compute the pressure in pascals of an ideal gas. Applies the ideal gas law: http://en.wikipedia.org/wiki/Ideal_gas_law v -- volume of gas, in cubic meters t -- absolute temperature in degrees kelvin n -- particles of gas """ k = 1....

2024-01-22 · 2 min