Advertisement
gruntfutuk

diamond without recursion

Jun 6th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. def diamond(rows):
  2.     spaces = " " * (rows * 2)
  3.     stars = "* "
  4.     for _ in range(rows):
  5.         print(f"{spaces}{stars}")
  6.         spaces = spaces[2:]
  7.         stars += "* * "
  8.     for _ in range(rows + 1):
  9.         print(f"{spaces}{stars}")
  10.         spaces += "  "
  11.         stars = stars[4:]
  12.        
  13. try:
  14.     height = int(input('Enter height (>4 and odd): '))
  15.     if not height > 4 or not height & 1:
  16.         raise ValueError
  17. except ValueError:
  18.     print('That is not going to work')
  19.     height = None
  20.                  
  21. if height:
  22.     diamond(int(height/2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement