【发布时间】:2014-11-01 13:46:08
【问题描述】:
我写的代码是生成斐波那契数列到用户选择的点,例如'10'会生成:
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
问题是空白,我想知道是否可以让它像这样打印:
[1,1,2,3,5,8,13,21,34,55]
没有空格。
这是我正在使用的代码:
a=int(input("write the length of numbers you would like to see the fibonacci series for(by entering 0 or 1 the output will be [1,1]): "))
if a<0:
print("invalid entry please type a positive number")
else:
i=2
fibs=[1,1]
b=fibs[-2]
c=fibs[-1]
d=b+c
while i<a :
i=i+1
b=fibs[-2]
c=fibs[-1]
d=b+c
fibs.append(d)
print(fibs)
【问题讨论】:
-
您无法选择
list的表示形式,但您可以自己格式化输出。 -
我个人喜欢在某些情况下按原样对待对象,如果我愿意自定义gist.github.com/anonymous/edec7353fa8b61e66e2d