I have written a program where I need to input a length and it returns the digits in the Fibonacci number sequence.
Write a program that given an input n, outputs the first n Fibonacci numbers. The format of the output is that at most 4 numbers can be displayed in a row.
My problem is, when i run the program the output shows [0, 1, 1, 2, 3, 5, 8, 13, 21, 34].
I need the solution to show 4 numbers per row ie
0 1 1 2
3 5 8 13
21 34
Please find attached my code.
def number(n):
if n ==1:
print(0)
else:
li = [0, 1]
for i in range(2, n): # start the loop from second index as 'li' is assigned for 0th and 1st index
li.append(li[-1] + li[-2])
i += 1
print(li)
n = int(input('Enter a positive number:'))
number(n)
Can you please explain how I can achieve the desired result?