-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMD-Fibonacci-recursive.py
97 lines (78 loc) · 2.71 KB
/
CMD-Fibonacci-recursive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""Python CMD program for printing Fibonacci series from 0 to input value(number_Of_Series) with a recursive function.
using Python version 3.11.4
@version : 1.0
@license: MIT License
@author : Arman Azarnik
contact me at : armanazarnik@gmail.com
"""
def main():
"""
main function for interacting with the user
"""
while(True):
# while loop to keep the program running
print("Please enter the number of Fibonacci series :")
number_Of_Series = int(input())
# casting the input string into integer
print("Your Fibonacci serie :")
result = store_Fibonacci_series_in_array(number_Of_Series)
# storing Fibonacci serie array in result variable
array_Printer(result)
# passing the result to the array_Printer to print each array element in a line
print("**************************************************")
def Fibonacci_Serie_Generator_Recursive(number):
"""
function for generating the Fibonacci series with a recursive function.
@param number: the input for serie number.
@type number: integer
@return: Fibonacci serie number
@rtype: integer
@examples:
>>> Fibonacci_Serie_Generator_Recursive(0)
>>> Fibonacci_Serie_Generator_Recursive(5)
3
"""
if(number == 1):
return 0
elif(number == 2):
return 1
else:
return Fibonacci_Serie_Generator_Recursive(number - 1) + Fibonacci_Serie_Generator_Recursive(number - 2)
def store_Fibonacci_series_in_array(number):
"""
function for storing the generated Fibonacci serie in an array.
@param number: the input for serie number.
@type number: integer
@return: Fibonacci_Series
@rtype: array of integers
@examples:
>>> Fibonacci_Serie_Generator_Recursive(0)
[]
>>> Fibonacci_Serie_Generator_Recursive(5)
[0, 1, 1, 2, 3]
"""
Fibonacci_Series = [None]*(number)
# initializing an empty array with lenght of number
for i in range(0, number):
Fibonacci_Series[i] = Fibonacci_Serie_Generator_Recursive(i+1)
# storing Fibonacci serie numbers, first number in index 0, second number in index 1 and ...
return Fibonacci_Series
def array_Printer(array):
"""
function for printing each array element in a line.
@param array: an array of elements.
@type array: anything like integer, double and string.
@examples:
array_1 = []
array_2 = [1, 2, 3]
>>> array_Printer(array_1)
>>> array_Printer(array_2)
1
2
3
"""
for element in array:
print(element)
if __name__ == '__main__':
main()
# run the main function after executing this file