Lab 3: Recursion, Tree Recursion(CS61A 2020)

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

(就此补充一下答案)

Q2: WWPD: Journey to the Center of the Earth

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 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

你可能感兴趣的:(python,linux,开发语言)