Very late to the party here, but wanted to post another python solution.
Takes advantage of using string formatting to center the text, simplifying the code, also using chain from itertools to stack to range functions together.
from itertools import chain def diamond(size): if size < 0 or not (size % 2): return None star = ( f"{'*'*l: ^{size}}" for l in chain( range(1, size, 2), range(size, 0, -2) ) ) return "\n".join(star) if __name__ == "__main__": print(diamond(11))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Very late to the party here, but wanted to post another python solution.
Takes advantage of using string formatting to center the text, simplifying the code, also using chain from itertools to stack to range functions together.