File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Problem Solving in Python/01_Basic Problems/Solutions Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ # Approach 1: Fibonacci Series [in Limit]
2+ def generateFibonacci (limit ):
3+ fibonacci_numbers = []
4+ a ,b = 0 ,1
5+ while a <= limit :
6+ fibonacci_numbers .append (a )
7+ a ,b = b , b + a
8+ return fibonacci_numbers
9+
10+ limit1 = int (input ("Enter the limit: " ))
11+ print (generateFibonacci (limit1 ))
12+
13+ # Approach 2: Fibonacci Series [in Range]
14+ limit = int (input ("Enter the limit: " ))
15+ a ,b = 0 ,1
16+ fibonacci_numbers = [a ,b ]
17+ for i in range (2 ,limit ):
18+ c = a + b
19+ fibonacci_numbers .append (c )
20+ a = b
21+ b = c
22+ print (fibonacci_numbers )
23+
24+ # Approach 3: Fibinacci Numbers [in Range]
25+ limit = int (input ("Enter the limit: " ))
26+ a ,b = 0 ,1
27+ fibonacci_numbers = [a ,b ]
28+ for i in range (2 ,limit ):
29+ fibonacci_numbers .append (c )
30+ a ,b = b , a + b
31+ print (fibonacci_numbers )
You can’t perform that action at this time.
0 commit comments