Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fibonacci Python #1

Open
Phlotonic opened this issue Feb 13, 2023 · 0 comments
Open

Fibonacci Python #1

Phlotonic opened this issue Feb 13, 2023 · 0 comments

Comments

@Phlotonic
Copy link
Owner

Define a function to find the nth Fibonacci number def fibonacci(n): # Base cases: 0 and 1 if n == 0: return 0 elif n == 1: return 1 # Recursive case: use the formula F(n) = F(n-1) + F(n-2) else: return fibonacci(n-1) + fibonacci(n-2) # Ask the user for a positive integer n = int(input("Enter a positive integer: ")) # Print the Fibonacci sequence up to the nth term print("The Fibonacci sequence up to the", n, "th term is:") for i in range(n): print(fibonacci(i), end=" ")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant