Skip to content
doubtly

1 answer

Best answer

Answer: Generate Fibonacci terms and keep printing while the term is 50 or less. Output: 0 1 1 2 3 5 8 13 21 34

a, b = 0, 1
print("Fibonacci series between 0 and 50:")
while a <= 50:
    print(a, end=" ")
    a, b = b, a + b
print()

How it works

  • a and b start as the first two terms, 0 and 1.
  • Each pass prints a, then a, b = b, a + b moves one step along the series (each term is the sum of the previous two).
  • The while a <= 50 condition stops the loop at the first term above 50 (55), so only the terms between 0 and 50 are printed.
Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.