0

Print a Fibonacci series till specific range

mandatory to print error if range is smaller than starting number

29th Jun 2018, 9:51 PM
Shashwat Bajpai
Shashwat Bajpai - avatar
3 Respuestas
30th Jun 2018, 4:59 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
0
def fibo(n): if n==1: print ([0]) return if n==2: print ([0,1]) return else: l = [0,1] for i in range(n-2): l.append(l[-1] + l[-2]) print(l) fibo(3)
30th Jun 2018, 5:05 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
0
You can nth Fibonacci number: def fibo(n): if n==1: return 0 if n==2: return 1 else: l = [0,1] for i in range(n-2): l.append(l[-1] + l[-2]) print(l[-1]) fibo(6) ================================== def fib(n): a, b = 0, 1 if n == 1: return 0 if n == 2: return 1 else: n -= 2 while n: a, b = b, a+b n = n -1 return b print(fib(6))
30th Jun 2018, 5:16 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar