Write a Python program that prints the Fibonacci series up to n terms. The integer n is input by the user.
Example 1:
Input: 5
Output: 0, 1, 1, 2, 3
Example 2:
Input: 10
Output: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
In the Fibonacci series, the next number is the sum of the previous two numbers. You can start by initializing two variables to 0 and 1.
def print_fibonacci(n):
a, b = 0, 1
for i in range(n):
print(a, end=' ')
a, b = b, a + b
print_fibonacci(5)
NOTEOwing to browser caching, any code input into the Trinket IDE might carry over across page refreshes or when transitioning between different questions. To commence with a clean slate, either click on the 'Reset Button' found within the IDE's Hamburger icon (☰) menu or resort to using Chrome's Incognito Mode.