Just submitted my kata. <3 codewars. Start from the middle, and go on appending stars to the top and bottom respectively.
Python:
def is_negative(n): return n <= 0 def is_even(n): return n % 2 == 0 def stars_with_spaces(num_stars, num_spaces): return num_spaces * ' ' + num_stars * '*' + '\n' def diamond(n): if (is_negative(n) or is_even(n)): return None res = [None] * n mid_point = int((n - 1) / 2) num_stars = n num_spaces = 0 for i in range(mid_point + 1)[::-1]: stars = stars_with_spaces(num_stars, num_spaces) res[mid_point - num_spaces] = stars res[mid_point + num_spaces] = stars num_spaces += 1 num_stars -= 2 return ('').join(res)
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.
Just submitted my kata. <3 codewars.
Start from the middle, and go on appending stars to the top and bottom respectively.
Python: