File tree Expand file tree Collapse file tree
students/brian_warn/session02 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/Library/Frameworks/Python.framework/Versions/3.6/bin/python
2+ # series.py
3+
4+ def main ():
5+ def fibonacci (n ):
6+ ''' Compute fibonacci series for a given input number
7+ :arg input integer
8+ :return: nth value in the fibonacci series
9+ '''
10+ if n == 0 :
11+ return 0
12+ if n == 1 :
13+ return 1
14+ return fibonacci (n - 1 ) + fibonacci (n - 2 )
15+
16+ def lucas (n ):
17+ ''' Compute Lucas Numbers series for a given input number
18+ :arg input integer
19+ :return: nth value in the Lucas Numbers series
20+ '''
21+ if n == 0 :
22+ return 2
23+ if n == 1 :
24+ return 1
25+ return luc (n - 1 ) + luc (n - 2 )
26+
27+ def sum_series (n , a = 0 , b = 1 ):
28+ ''' Compute Lucas Numbers series or Fibonacci series based upon optional parameter values
29+ :arg
30+ n = input integer
31+ a = first optional argument
32+ b = second optional argument
33+ :return: nth value in either the Lucas Numbers series or Fibonacci series
34+ '''
35+ if a == 0 and b == 1 :
36+ result = 'Fibonacci Sequence Result for ' + str (n ) + ' is :' + fibonacci (n )
37+ return result
38+
39+ def run_program ():
40+
41+ n_value = int (input ("Input nth value to be computed: " ))
42+ first_number = str (input ("Provide the first number of the series: " ))
43+ second_number = str (input ("Provide the second number of the series: " ))
44+ if first_number == '' :
45+ first_number = int (0 )
46+ if second_number == '' :
47+ second_number = int (1 )
48+ output = sum_series (n_value , first_number , second_number )
49+ print (output )
50+
51+ run_program ()
52+
53+ if __name__ == "__main__" :
54+ main ()
You can’t perform that action at this time.
0 commit comments