Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

can Anyone help me to solve it

The fibonacci numbers are defined by the sequence f1=1 f2=1 fn=f(n-1)+f(n-2) Reformulate that as fold1=1 fold2=1 fnew = fold1+fold2 After that , discard fold2 , which is no longer needed , and set fold2 to fold1 and fold1 to fnew. Implement a program that prompts that asks the user for an integer n and prints the nth Fibonacci number , using the above algorithm.

2 Answers

Steven Parker
Steven Parker
243,266 Points

I hope you're not asking for someone to do your homework! :see_no_evil:

But this is a classic programming problem and you should be able to easily find sample solutions to it using your favorite search engine.

I am not asking anyone to do my homework, I am asking the way of how to solve

thanks

Steven Parker
Steven Parker
243,266 Points

Khumoyunmirzo Nosirov — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!