本文介绍: 【代码】Lab 3: Recursion, Tree Recursion(CS61A 2020)

网上没有lab3相应的答案作者也卡蛮久

(就此补充一下答案

Use Ok to test your knowledge with the following “What Would Python Display?” questions:

python3 ok -q sr-wwpd -u

For all WWPD questions, type Function if you believe the answer is <function...>Error if it errors, and Nothing if nothing is displayed.

>>> def crust():
...     print("70km")
...     def mantle():
...          print("2900km")
...          def core():
...               print("5300km")
...               return mantle()
...          return core
...     return mantle
>>> drill = crust
>>> drill = drill()

>>70km

>>> drill = drill()

>>2900km

>>> drill = drill()

>>5300km
>>2900km

>>> drill()

>>5300km
>>2900km
>>Function

1.之前的drill=drill()只是调用

但不返回其值或类型(因为是赋值行为

2.最后一个drill()

可以理解为,

函数调用过程打印两个值,并返回drill()的类型–>function

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注