I wrote this code for a fibonacci sequence generator. Can anyone tell me whether my code is designed well? if not, why?
import logging
def fibonacci_calc(current_val, current_pos=0, max_seq_length=5, sequence_list=[]):
try:
if(current_pos != 0 and len(sequence_list) == 0):
raise Exception("Please initalize {} argument: {} with 0".format(fibonacci_calc.__name__, fibonacci_calc.__code__.co_varnames[1]))
else:
if(len(sequence_list) == 0):
print("Initialization, added 0 and starting number {} to sequence list".format(current_val))
sequence_list.append(0)
sequence_list.append(current_val)
current_pos = 1
print(sequence_list)
fibonacci_calc(current_val, current_pos, max_seq_length, sequence_list)
elif(len(sequence_list) == max_seq_length):
print('{} values in the sequence'.format(max_seq_length))
return
else:
print("Current position: {}, Total values: {} calculating next value".format(current_pos, current_pos+1))
next_val = sequence_list[current_pos] + sequence_list[current_pos-1]
sequence_list.append(next_val)
print("Current sequence list {}".format(sequence_list))
fibonacci_calc(next_val, current_pos+1, max_seq_length, sequence_list)
except Exception:
logging.exception('ERROR')
fibonacci_calc(19,0, 7)
fibonacci_calc(19,0, 7)call you already do. \$\endgroup\$