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