Question: Question: This program should display FOUR different shapes. Each of the FOUR shapes corresponds to one of the characters 'A', 'B', 'C', 'D'. Between them,
Question:
This program should display FOUR different shapes. Each of the FOUR shapes corresponds to one of the characters 'A', 'B', 'C', 'D'. Between them, the four different shapes you create should at least contain a rectangle, an oval and a line and must include at least two different colours. As well as the four characters corresponding to each shape, the '_' character corresponds to a blank space in the grid, i.e., a missing shape. The size into which each shape fits, the number of rows, the number of shapes in each row and the sequence of shapes are all randomly generated by the program.
(a)Complete the get_row_of_shape_symbols(number_of_shapes) function.
Each row displays a sequence of random shapes for that row. To get the sequence of shapes the program randomly generates a series of letters 'A', 'B', 'C', 'D' or '_' where the '_' symbol means there is a blank space in the row (a missing shape). Complete the get_row_of_shape_symbols() function. This function is passed an integer parameter. The function returns a string made up of the parameter number of random characters from the string "ABCD_". The first line of this function is:
possible_shapes = "ABCD_"
b) Complete the get_pattern_info_tuple() function.
Complete the get_pattern_info_tuple()function. This function:
generates a random number between 10 and 25 (both inclusive) - the size into which each shape fits,
generates a random number between 8 and 15 (both inclusive) - the number of rows in the grid of shapes, and,
for each row of the grid, the function generates a random number between 10 and 20, both inclusive (the number of shapes in each row), makes a call to the get_row_of_shape_symbols() function from Question 1 b) above and appends the string returned by this function call to a list.
The function returns a tuple made up of the size integer and the list of strings generated.
c) Complete the draw_pattern(a_canvas, size, rows_of_shapes_list) function.
Complete the draw_pattern() function. This function is passed three parameters:
a_canvas: the canvas in which the grid of shapes is drawn,
size: the square area into which each shape fits,
rows_of_shapes_list: a list of strings denoting the sequence of shapes which are to be displayed in each row of the grid.
The function draws the grid of shapes where each row is made up of the sequence of shapes corresponding to the characters in each string of the rows_of_shapes_list parameter list. An example shape sequence is the string "D_CDDBBACBA_ADA". The sequence of shapes corresponding to this string is: the shape corresponding to the letter 'D', followed by a blank space, followed by the shape corresponding to the letter 'C', followed by two shapes corresponding to the letter 'D', followed by two shapes corresponding to the letter 'B', followed by the shape corresponding to the letter 'A', etc. Note: the left top of the pattern is one grid square from the left and one grid square from the top.
d) Complete the print_pattern_info(size, rows_of_shapes_list) function.
Complete the print_pattern_info()function which is passed two parameters: the size (an integer) and the list of strings denoting the sequence of shapes which are displayed in each row of the grid. This function prints the following lines of output:
the string "Pattern info:"
the string "Size: ", followed by the size parameter, followed by the string, " pixels, Number of rows: " followed by the number of rows in the pattern.
two blank lines
the string "Pattern of shapes in each row:"
and finally, each element of the rows_of_shapes_list parameter. Each element is printed on a single line and is preceded by two spaces.
AN EXAMPLE OF THE OUTPUT:

THE CODES ARE:
from tkinter import * import random
#------------------------------------------- #------------------------------------------- # a) Make one change to the main() function #------------------------------------------- def main(): canvas_width = 25 * 23 canvas_height = 25 * 17 window = Tk() window.title("A5 Question 1 by") geometry_string = str(canvas_width)+"x"+str(canvas_height)+"+10+20" window.geometry(geometry_string) a_canvas = Canvas(window)
#a_canvas.config(background="SlateBlue1") a_canvas.pack(fill=BOTH, expand = True) #Canvas fills the whole top level window
size, rows_of_shapes_list = get_pattern_info_tuple() print_pattern_info(size, rows_of_shapes_list)
draw_grid(a_canvas, size, canvas_width, canvas_height) draw_pattern(a_canvas, size, rows_of_shapes_list)
window.mainloop() #------------------------------------------- #------------------------------------------- # b) Complete the get_row_of_shape_symbols() function # c) Complete the get_pattern_info_tuple() function #------------------------------------------- def get_pattern_info_tuple(): return (0, [])
def get_row_of_shape_symbols(number_of_shapes): possible_shapes = "ABCD_" #------------------------------------------- #------------------------------------------- # d) Complete the draw_pattern() function #------------------------------------------- def draw_pattern(a_canvas, size, rows_of_shapes_list): pass #------------------------------------------- #------------------------------------------- # e) Complete the print_pattern_info() function #------------------------------------------- def print_pattern_info(size, rows_of_shapes_list): print() #------------------------------------------ # Draws the light blue background grid # of the given size #------------------------------------------ def draw_grid(a_canvas, size, right_hand_side, bottom): if size
main()
Pattern info: Size: 23 pixels, Number of rows: 8 An example grid of shapes and the corresponding output are shown here. A5 Question 1 by afer023 Pattern of shapes in each row: A CACBBA DC DBABCCDBA_CAA c_??_ADCAC CB_DACC BBB_CAAACCCCBCACD ??B DCB CCDB BAB BDA ABCBAADDDC AD_AA_AAC_BC TOOD DOO MOO O ODO MO
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
