Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Fibonacci Poem by arun_maiti
from collections.abc import Iterator
def fibo_poem(text: str) -> str:
def gen(it: Iterator[str]) -> Iterator[str]:
f0, f1 = 0, 1
while True:
line = " ".join(next(it, "_") for _ in range(f1))
if line.startswith("_"):
break
yield line
f0, f1 = f1, f0 + f1
it = iter(text.split())
return "\n".join(gen(it))
print("Example:")
print(fibo_poem("Zen of Python"))
# These "asserts" are used for self-checking
assert fibo_poem("") == ""
assert fibo_poem("Django framework") == "Django\nframework"
assert fibo_poem("Zen of Python") == "Zen\nof\nPython _"
assert (
fibo_poem("There are three kinds of lies: Lies, damned lies, and the benchmarks.")
== "There\nare\nthree kinds\nof lies: Lies,\ndamned lies, and the benchmarks."
)
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 5, 2025
Comments: