In Lab 4, we used functions in order to print a grid.
First i made a row and column and using parameters such as the definition do_twice, i was able to create two rows and two columns and so on, until i created my grid.
def print_beams() :
“””This function print the beams of a grid”””
print_beam()
print_beam()
print (“+”)
def print_posts() :
print_post()
print_post()
print(“|”)
def print_row() :
“””This function prints a row of the grid”””
print_beams()
print_posts()
print_posts()
print_posts()
print_posts()
def print_grid() :
“””This function prints the entire grid using do_twice”””
do_twice(print_row)
print_beams()
print_grid()
Version 2: def do_twice(f) :
“””This function invokes twice the function pass as parameter”””
f()
f()
def do_four(f) :
“””This function invokes 4x pass parameter”””
do_twice(f)
do_twice(f)
def print_beam():
print (“+ – – – – “, end=”)
def print_post() :
print (“| “, end=”)
def print_beams() :
“””This function print the beams of a grid”””
print_beam()
print_beam()
print_beam()
print_beam()
print (“+”)
def print_posts() :
print_post()
print_post()
print_post()
print_post()
print(“|”)
def print_row() :
“””This function prints a row of the grid”””
print_beams()
print_posts()
print_posts()
print_posts()
print_posts()
def print_grid() :
“””This function prints the entire grid using do_twice”””
do_twice(print_row)
do_twice(print_row)
print_beams()
print_grid()