Skip to content

Instantly share code, notes, and snippets.

@steve3535
Created April 7, 2025 14:03
Show Gist options
  • Save steve3535/e8a10df3d37e9e31adfe8e69db499aa3 to your computer and use it in GitHub Desktop.
Save steve3535/e8a10df3d37e9e31adfe8e69db499aa3 to your computer and use it in GitHub Desktop.
def calculate_fibonacci(n):
"""
Calculate the nth number in the Fibonacci sequence.
Args:
n (int): The position in the sequence (starting from 0)
Returns:
int: The Fibonacci number at position n
"""
if n <= 0:
return 0
elif n == 1:
return 1
else:
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b
# Example usage
if __name__ == "__main__":
for i in range(10):
print(f"Fibonacci({i}) = {calculate_fibonacci(i)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment