Created
April 7, 2025 14:03
-
-
Save steve3535/e8a10df3d37e9e31adfe8e69db499aa3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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