我寫的代碼以產生所述斐波納契數列由用戶所選擇的點,例如「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」表示的選擇,但您可以自己格式化輸出。 – jonrsharpe 2014-11-01 13:47:19
我個人喜歡在某些情況下對待對象,因爲他們真的是,如果我認爲自定義https://gist.github.com/anonymous/edec7353fa8b61e66e2d – neiesc 2014-11-01 14:42:49