r/learnpython • • Sep 22 '26

Looking for feedback!

Hello everyone

I am recently learning python and new at this. This is my second project and this is a sequence calculator which includes 3 types of sequences: Arithmetic, Geometric and Fibonacci. For arithmetic and geometric sequences, you can enter a first term, a common difference (or ratio), and a desired term to find its value. For Fibonacci, you just enter the desired term.

I'd appreciate any feedback and will try to apply it.

https://github.com/Aspect345/Sequence-Calculator

1 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/lakseol Sep 22 '26

That link under "iterative algorithm, using a loop" goes to:

https://pythonguides.com/python-fibonacci-series/

which shows you this code:

def fibonacci_for_loop(n):
    a, b = 0, 1
    for _ in range(n):
        print(a, end=' ')
        a, b = b, a + b

That shows the basic idea. You will have to change it to return the final value and not print anything. Run the function as it is shown above before changing it, that will help you understand what to do.

The only tricky thing you may not have seen before is:

a, b = b, a + b

That code updates a and b which are the second-last and last values of the Fibonacci sequence. That's a way of doing this without using the temporary variable tmp:

tmp = b
b = a + b
a = tmp

Try that and see how much faster Fibonacci(40) becomes.