How to print the Fibonacci sequence in one line using python?

Question:

I just need to print the sequence in one line, how do I do that? Thanks to those who’ll answer

n = input("Enter n: ")

def fib(n):
    cur = 1
    old = 1
    i = 1
    while (i < n):
        cur, old, i = cur+old, cur, i+1
    return cur

for i in range(10):
    print(fib(i))
Asked By: Shin

||

Answers:

Add a argument in print() function:

print(fib(i), end=" ")
Answered By: nnzzll

by default, the print function ends with a newline "/n" character

You can replace that with whatever character you want with the end keyword argument

e.g.

print(fib(i), end = " ")
Answered By: Jim