Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Students/salim/draw_box.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
def print_grid(size, boxes):

# adjust wrong inputs
size, boxes = adjust_inputs(size, boxes)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice use of separate functions to keep it clean.


# rows of grid
row_count = 0
for i in range(size):

# if row is a solid line
if row_count % (size / boxes) == 0:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do the "simpler":
if not row_count % (size / boxes):

(zero evaluates at False)


print_row(width=size, row_type='solid', boxes=boxes)

# if row is a non-solid line
else:

print_row(width=size, row_type='non-solid', boxes=boxes)

# increment row_count
row_count += 1


def print_row(width, row_type, boxes):

# set row type
if row_type == 'solid':
outside = '+'
inside = '-'
elif row_type == 'non-solid':
outside = '|'
inside = ' '

# columns of row
col_count = 0
for ii in range(width):

# if middle of row
if col_count < (width - 1):

if col_count % (width / boxes) == 0:
print outside, # include commas to keep text on same line
else:
print inside, # include commas to keep text on same line

# if end of row
else:

if col_count % (width / boxes) == 0 or boxes == 1:
print outside
else:
print inside

# increment col_count
col_count += 1


def adjust_inputs(size, boxes):

# if size input is even, change to next biggest odd number
if size % 2 == 0:
size_result = size + 1
else:
size_result = size

# min of boxes value 1 and boxes value not greater than size_result
if boxes <= 1:
boxes_result = 1
elif boxes > size_result:
boxes_result = size_result
else:
boxes_result = boxes

return size_result, boxes_result