Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Draw a grid of any size, up to 32 cells in each direction!")
- def checknum(d):
- msg = "Please enter a whole number between 1 and 32."
- while True:
- fin = input("Enter the number of cells " + d + ": ")
- try:
- fin = float(fin)
- except ValueError:
- print(msg)
- continue
- if fin < 1 or fin > 32:
- print(msg)
- continue
- fout = int(fin)
- if fin != fout:
- print(msg)
- continue
- break
- return fout
- x = checknum("across")
- y = checknum("down")
- lines = []
- #top border
- lines.append("╔═")
- for i in range(x-1):
- lines[0] += "╤═"
- lines[0] += "╗"
- #first row of cells
- lines.append("║")
- for i in range(x-1):
- lines[1] += " │"
- lines[1] += " ║"
- #rest of the rows and inner horizontal lines
- for i in range(2,2*y,2):
- lines.append("╟")
- rowline=""
- for j in range (x-1):
- rowline += "─┼"
- lines[i] += rowline + "─╢"
- lines.append(lines[1])
- #bottom border
- lines.append("╚═")
- for i in range(x-1):
- lines[len(lines)-1] += "╧═"
- lines[len(lines)-1] += "╝"
- for i in range(len(lines)):
- print(lines[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement