Write a program using list comprehension to print the Fibonacci Sequence in comma separated form with a given n input by console.


Topic: Write a program using list comprehension to print the Fibonacci Sequence in comma separated form with a given n input by console.

Solution

def f(n):
    if n == 0: return 0
    elif n == 1: return 1
    else: return f(n-1)+f(n-2)
n=int(raw_input())
values = [str(f(x)) for x in range(0, n+1)]
print ",".join(values)



List all Python Programs