|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求大佬帮忙看一下这个题怎么做啊!
# The Fibonacci sequence is 0, 1, 1, 2, 3, 5, ... where each
# subsequent number is equal to the the preceeding two.
# This means the next elements in the list above would be 8 (5 + 3)
# and 13 (8 + 5)
#
# The 9th element in the sequence is 21. Let's call this the `current` value.
# The 8th element in the sequence is 13. Let's call this the `last` Value.
#
# Using PARALLEL ASSIGNMENT/TUPLE UNPACKING, perform the following operations
# in a single statement
# 1. replace the value of `current` with the value of the 10th
# element in the sequence (so the sum of the 8th and 9th element)
# 2. replace the value of `last` with the value of the 9th element
# Leave this here
current = 21 # at this point, the 9th element of the sequence
last = 13 # at this point, the 8th element of the sequence
# Now, use parallel assignment to replace the value of `current` and `last`
# (put your answer below)
本帖最后由 isdkz 于 2023-3-1 22:32 编辑
它说的是 python 的两个特性:并行赋值(PARALLEL ASSIGNMENT)和 元组解包 (TUPLE UNPACKING)
题目的要求是把 current 替换成斐波那契数列的第 10 个元素的值,把 last 替换成 斐波那契数列的第 9 个元素的值,
而且题目已给出的代码中 last 和 current 恰好是斐波那契数列的第 8 个元素和第 9 个元素的值,
所以同时运用并行赋值和元组解包的代码为:current, last = current + last, current
|
|