Advertisement
gruntfutuk

Diamond with recursion

Jun 6th, 2019
175
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(start, fini, half):
  2.     if start < fini:
  3.         if start <= half:
  4.             print(f"{'  ' * (half - start)}{'* ' * ((start << 1) + 1)}")
  5.         else:
  6.             print(f"{'  ' * (start - half)}{'* ' * ((fini - start << 1) - 1)}")
  7.         diamond(start + 1, fini, half)
  8.                  
  9. try:
  10.     height = int(input('Enter height (>4 and odd): '))
  11.     if not height > 4 or not height & 1:
  12.         raise ValueError
  13. except ValueError:
  14.     print('That is not going to work')
  15.     height = None
  16.                  
  17. if height:
  18.     diamond(0, height, height >> 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement