这是代码
import sys
n=int(sys.argv[1])
first = 0
nexter = 0
second = 1
print(first,second)
for i in range(0,n-2):
nexter = first+second
print(nexter,end=" ")
first=second
second=nexter
输出正在得到
0 1
1 2 3
但是,我想要的输出是
0 1 1 2 3
我该怎么做?
答案 0 :(得分:1)
因此,您已经在print(nexter,end=" ")
处合并了多个打印件。这意味着要用空格结束打印。您的操作与print(first,second ,end=" ")
相同。完整的代码:
import sys
n=int(sys.argv[1])
first = 0
nexter = 0
second = 1
# Only make this change of ending the print with " ". The default is a new line character.
print(first,second ,end=" ")
for i in range(0,n-2):
nexter = first+second
print(nexter ,end=" ")
first=second
second=nexter