Skip to content

Instantly share code, notes, and snippets.

@akashmdiu
Created May 29, 2023 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akashmdiu/dd447ba53f322bf46ef12b5d73e30d48 to your computer and use it in GitHub Desktop.
Save akashmdiu/dd447ba53f322bf46ef12b5d73e30d48 to your computer and use it in GitHub Desktop.
# Title: Calculate Fibonacci Sequence
# Description: A Python function to calculate the Fibonacci sequence up to a specified number of terms.
def fibonacci(n):
sequence = [0, 1]
while len(sequence) < n:
next_number = sequence[-1] + sequence[-2]
sequence.append(next_number)
return sequence
# Example usage
fib_sequence = fibonacci(10)
print(fib_sequence)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment