Advertisement
mengyuxin

meng.boxPrint.py

Jan 3rd, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. #! python3
  2. # boxPrint.py - testing for try catch
  3.  
  4. def boxPrint(symbol, width, height):
  5.     if len(symbol) != 1:
  6.         raise Exception('Symbol must be a single charater string.')
  7.     if width <= 2:
  8.         raise Exception('Width must be greater than 2.')
  9.     if height <= 2:
  10.         raise Exception('Height must be greater than 2.')
  11.        
  12.     print(symbol * width)
  13.    
  14.     for i in range(height -2):
  15.         print(symbol + (' '* (width - 2)) + symbol)
  16.        
  17.     print(symbol * width)
  18.  
  19. for sym, w, h in (('*', 4, 4), ('0', 20, 5), ('x', 1, 3), ('ZZ', 3, 3)):
  20.     try:
  21.         boxPrint(sym, w, h)
  22.     except Exception as err:
  23.         print('An exception happened: ' + str(err))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement