Gave it a try in Python. Not exactly as required since the diamond is printed on-the-fly, but I think it shows the main idea to create every line one after the other. Could also be stored in a string and then returned...
import sys def diamond(width): padding = width//2 while padding > -width//2: print(" " * abs(padding) + "*" * (width - abs(padding) * 2)) padding -= 1 if (len(sys.argv) < 2 or int(sys.argv[1]) < 1 or int(sys.argv[1]) % 2 == 0): print("Invalid parameter") else: diamond(int(sys.argv[1]))
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.
Gave it a try in Python. Not exactly as required since the diamond is printed on-the-fly, but I think it shows the main idea to create every line one after the other. Could also be stored in a string and then returned...