Python Forum
Review for my Fibonacci sequence, please. (´。• ω •。`)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Review for my Fibonacci sequence, please. (´。• ω •。`)
#1
Lightbulb 
Salutations, Pythonistas! python
I hope you are all well and that your families and friends are doing well. ヽ(・∀・)ノ

I have developed a simple piece of code that prints the Fibonacci sequence. I would like to get feedback on my novice coding skills from people more experienced than me. I applied things I have learned from courses, the official documentation and playing with the Python IDLE, ha, ha. Tongue

Before posting the code, I should clarify that the reason I avoided commenting on it was for two reasons:

  1. I would like to know how self-explanatory my code is.
  2. The truth is that I am terrible at it, ha, ha. Could you give me some advice, please?

That being said, now with you, the code:

def fibonacci(limit: int) -> 'Sequence in a List':
    n1, n2 = 0, 1
    accumulated: int = 0
    sequence: list = []
    while accumulated < limit:
        accumulated = n1 + n2
        n1 = n2
        n2 = accumulated
        sequence.append(accumulated)
    return sequence

while True:
    limit = input("Please, enter a limit for the sequence: ")
    try:
        print(fibonacci(int(limit)))
        break
    except ValueError:
        print(f"{limit} is not an integer.")
I'll stay tuned to the thread for any critiques, reviews, comments, etc. Thank you very much in advance, my friends! I hope your day is going well. ٩(。•́‿•̀。)۶
Reply


Messages In This Thread
Review for my Fibonacci sequence, please. (´。• ω •。`) - by Carmazum - Jun-06-2023, 03:26 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020