Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Fibonacci Poem by kdim
def fibo_poem(text: str) -> str:
a, b, text, poem = 0, 1, text.split(), []
while text:
row, text = text[:b], text[b:]
row.extend('_' * (b - len(row)))
poem.append(' '.join(row))
a, b = b, a + b
return '\n'.join(poem)
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!")
Jan. 21, 2023
Comments: