Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. print("Draw a grid of any size, up to 32 cells in each direction!")
  2.  
  3. def checknum(d):
  4. msg = "Please enter a whole number between 1 and 32."
  5. while True:
  6. fin = input("Enter the number of cells " + d + ": ")
  7. try:
  8. fin = float(fin)
  9. except ValueError:
  10. print(msg)
  11. continue
  12. if fin < 1 or fin > 32:
  13. print(msg)
  14. continue
  15. fout = int(fin)
  16. if fin != fout:
  17. print(msg)
  18. continue
  19. break
  20. return fout
  21.  
  22. x = checknum("across")
  23. y = checknum("down")
  24. lines = []
  25.  
  26. #top border
  27. lines.append("╔═")
  28. for i in range(x-1):
  29. lines[0] += "╤═"
  30. lines[0] += "╗"
  31.  
  32. #first row of cells
  33. lines.append("║")
  34. for i in range(x-1):
  35. lines[1] += " │"
  36. lines[1] += " ║"
  37.  
  38. #rest of the rows and inner horizontal lines
  39. for i in range(2,2*y,2):
  40. lines.append("╟")
  41. rowline=""
  42. for j in range (x-1):
  43. rowline += "─┼"
  44. lines[i] += rowline + "─╢"
  45. lines.append(lines[1])
  46.  
  47. #bottom border
  48. lines.append("╚═")
  49. for i in range(x-1):
  50. lines[len(lines)-1] += "╧═"
  51. lines[len(lines)-1] += "╝"
  52.  
  53. for i in range(len(lines)):
  54. print(lines[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement