Python code not working. Trying to compute two fibonacci numbers and find greatest common factor
Question: Can someone please help with this code. I'm attempting to write the simplest
program possible that reads in 2 numbers (m,n), then computes the nth
fibonacci number and the mth fibonacci number and then finds the greatest
common factor of the two inputted numbers. This is what I have so far. I'm new
to Python, so any help would be appreciated. Thanks in advance!

    
    
    def compute():
        m, n = -1, -1
        while m<0: m = int(input(“Please enter a positive number for m: “))
        while n<0: m = int(input(“Please enter a positive number for n: “))
        a, b = 1,1
        for i in (‘temp’, a+b), 
                 (‘a’, b), 
                 (‘b’, temp),
                 (‘mth’, b if i==m)
                 (‘nth’, b if i==m)
        for i in range(2, n+1)),:pass
        maxlen=0)
    return max(i for i in range(1, nth+1) if not mth%i and not nth%i)
    


Answer: In my opinion, when it comes to Python, the simplest answer might be either
the smallest piece of code or the code that's easiest to understand (and
sometimes both things are the same). Since you're starting with Python, I
think the easiest to understand is the best way to approach, but I reckon that
qwertyboys's answer might be also correct (and more advanced).

This is how I would do (I agree with user2357112's comment on splitting the
problem into two parts):

    
    
    first_num = int(input("Enter the first positive number: "))
    second_num = int(input("Enter the second positive number: "))
    
    fib_a, fib_b = 1, 1
    fib_sequence = [1, 1]
    
    for i in range (first_num + second_num):
        temp = fib_a + fib_b    
        fib_a = fib_b
        fib_b = temp
        fib_sequence.append(temp)
    
    from fractions import gcd
    
    print("Fibonacci sequence's #%s: %s" % (first_num, fib_sequence[first_num - 1]))
    print("Fibonacci sequence's #%s: %s" % (second_num, fib_sequence[second_num - 1]))
    print("Their Greatest Common Divisor is: %s" % gcd(fib_sequence[first_num - 1], fib_sequence[second_num - 1]))
    

I first created a Fibonacci's list that's long enough to fit both indexes, and
then picked the ones I wanted. An output example would be:

> Enter the first positive number: 3
>
> Enter the second positive number: 6
>
> Fibonacci sequence's #3: 2
>
> Fibonacci sequence's #6: 8
>
> Their Greatest Common Divisor is: 2

Although it's not the most elegant solution (yes, there is recursion and the
likes), I've tried to keep it clear on what's happening, hope it helps.
Remember that readability is a very important part of coding (specially on
Python) :)

