- 1
Write a program that reads 2 # call them n and m. Compute the nth fibonacci # and the mth fibonacci # and find the gcf
for example, if I typed in 11 and 16, the answer would be 5. the 11th fibonacci # is 55 and the 16th is 610. the greatest common factor is 5. You should ensure the user types in a positive # and ask if the user doesn't. I am looking to do this using python. any help is appreciated as I am very new to programming in general and specifically python
1 Réponse
0
This sounds like an assignment question, while asking for assignment code is frowned upon here, you are just asking for help in general - which i think is okay.
I will help lead you in a direction, but you must write the code yourself.
Fibonacci sequence is a popular pattern that is found in nature. It's very easy to compute. The sequence starts at 0, then followed by 1. Then every number that follows is the sum of the previous two numbers.
0, 1, 1, 2, 3, 5, 8, 14 ........
In your question, you're trying to find the value at a given n-th time, which if you follow the sequence above, will help you get there. One variable can track position, while the other computes the sum.
There are tons of ways to approach this, either with list/arrays, or recursive functions.
The rest of your question I believe you should be able to handle since it asks things like making sure the input is positive, etc.