0

How to print a fibonacci series as output using user input

13th Feb 2017, 4:31 PM
saipranay
2 Respuestas
+ 1
x = input ("Fibonacci series") print (x) LOL (I'm idiot)
19th Feb 2017, 12:03 AM
Kafir
Kafir - avatar
0
1- You enter a number. 2- if your number is less or equal to 2, the result would be 1. 3- if your number is strictly greater than 2, say X. You return (X-2) + (X-1) and keep calling the same function. Here is my code using a function call def fibonacci(n): if n <= 2: return 1 else: return (fibonacci(n-1) + fibonacci(n-2)) x = input("ENTER YOUR NUMBER: ") print(fibonacci(x))
20th Feb 2017, 6:17 AM
Abdelkader Ait Assou
Abdelkader Ait Assou - avatar