我想我要做的是从一个定义的列表中显示一个select部分。目前我正在处理的是:
#fibonacci sequence algorithm, user stops by either
#entering a maximum Fibonacci value not to exceed or
#a total count that the sequence of numbers must not
#exceed. Use a loop that allows User to repeat program
#as much as they wish, asking if they would like to
#repeat the program each time. Validate that User input
#is either a yes or a no and only allow User to continue
#once a correct response has been given.
import array
array.listOfFibSeq = ['0','1','1','2','3','5','8','13','21','34','55','89','144','...']
startingNumber = ''
endingNumber = ''
continueYes = ''
def getStartingNumber():
print('Please enter a valid starting number of the Fibonacci Sequence')
print(listOfFibSeq)
startingNumber = input()
def getEndingNumber():
print('Please enter a valid ending number the the Fibonacci Sequence')
print(listOfFibSeq)
endingNumber = input()
我不知道该怎么做,但我相信我正在尝试用斐波纳契数列显示(例如)3到89,或者做一些类似的事情:
^{pr2}$或者我应该用for循环显示Fib序列的一个范围吗?在
在用户输入一个范围之前,没有合理的方法来预计算fibonacci序列-您应该动态地这样做。在
一种简单的方法是使用一个函数来计算给定的
(a, b)
的序列,一直到end
,丢弃直到start
的所有内容。在我更喜欢发电机方法:
或者,在你的情况下,类似于:
^{pr2}$相关问题 更多 >
编程相关推荐