Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate the Fibonacci Sequence for the length given
def gen_fibonacci_sequence(length):
fibonacci_sequence = ["1", "1"]
for num in range(2, length):
prev_num = int(fibonacci_sequence[num - 1])
prev_prev_num = int(fibonacci_sequence[num - 2])
curr_num = prev_num + prev_prev_num
fibonacci_sequence.append(str(curr_num))
return fibonacci_sequence
def main():
fibonacci_sequence = " ".join(gen_fibonacci_sequence(10))
print(fibonacci_sequence)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment