File tree 1 file changed +13
-11
lines changed
1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change 1
1
# Fibonacci Sequence Using Recursion
2
2
3
3
def recur_fibo (n ):
4
- if n <= 1 :
5
- return n
6
- else :
7
- return (recur_fibo (n - 1 ) + recur_fibo (n - 2 ))
4
+ return n if n <= 1 else (recur_fibo (n - 1 ) + recur_fibo (n - 2 ))
8
5
9
- limit = int (input ("How many terms to include in fibonacci series: " ))
6
+ def isPositiveInteger (limit ):
7
+ return limit >= 0
10
8
11
- if limit <= 0 :
12
- print ("Please enter a positive integer: " )
13
- else :
14
- print (f"The first { limit } terms of the fibonacci series are as follows" )
15
- for i in range (limit ):
16
- print (recur_fibo (i ))
9
+ def main ():
10
+ limit = int (input ("How many terms to include in fibonacci series: " ))
11
+ if isPositiveInteger :
12
+ print (f"The first { limit } terms of the fibonacci series are as follows:" )
13
+ print ([recur_fibo (n ) for n in range (limit )])
14
+ else :
15
+ print ("Please enter a positive integer: " )
16
+
17
+ if __name__ == '__main__' :
18
+ main ()
You can’t perform that action at this time.
0 commit comments