Question: CSc 1 2 0 : Word Grid This problem involves learning to use Python s random number generator. Restrictions For the long problems, your code
CSc : Word Grid
This problem involves learning to use Pythons random number generator.
Restrictions
For the long problems, your code should follow the style guidelines for the class. You must following the updated guidelines for commenting classes.
You may not use concepts andor shorthand syntax not yet covered in class. The restrictions include the following:
Python dictionaries
dictionary or list comprehensions, egn for i in range
with open explicitly open and close the file instead
the ternary operator use an if instead
recursion
exceptions tryexcept
type annotations
lambda expressions
importing libraries except the random library for this word grid problem
File Names
Your program should be in a file named wordgrid.pyNOTE: use an underscore, not a dash.
Expected Behavior
First recall that a grid is a dlist that is a list of lists where the length of each inner list is the same length as the outer list. Your program should read two integer values from the input. The first value is the grid size. The second is a random number seed. The program should use the random number seed to initialize the random number generator, create a grid of size grid size times grid size of randomly generated lowercase letters and, finally, print out the grid of letters one row per line.
Specifically, write a program, in a file named wordgrid.py that behaves as follows:
At the top of your program after the header comment, import the module random:
import random
Write a function init with no argument, that does the following:
Use the input function with no argument to read in the value of gridsize as the first value read in
Use the input function with no argument to read in the value of seedvalue as the second value read in
Initialize the random number generator with the value seedvalue.
Note that your code should not prompt the user for input that is you should not supply a string to display to the user Your program will simply read in two numbers and treat the first one as the grid size which needs to be an integer and the second one as the seed which needs to remain a string Use the following code to initialize the variables gridsize and seedvalue, and then intialize the random number generator:
gridsize intinput
seedvalue input
random.seedseedvalue
Return gridsize as the return value of the function.
Write a function makegridgridsize that takes an integer argument gridsize and creates a grid of size gridsize times gridsize whose elements are randomly generated letters. The function returns the grid created.
Notes:
each row of the grid is represented as a list of length gridsize; and
the grid then consists of a list of gridsize such rows.
For example: the grid
a b c
d e f
g h i
is represented as the list of lists
abcdefghi
Write a function printgridgrid that takes a list of lists grid as an argument and prints it out one row per line, with a single comma after each letter except for the last one in the row.
For example, the grid
pqrstuvwxyzabcde
is printed out as
pqrs
tuvw
xyza
bcde
Note: The indentation in this example is just to improve readability. The output from your printgrid function should not have any whitespace at the beginning of any line for indentation purposes.
Write the main function to do the following:
call init which returns the grid size;
call makegrid with the grid size as an argument; the function returns the grid created
call printgrid using the grid returned by makegrid as its argument; print out the grid.
Programming Requirements
When converting from a random number to a letter, do not use a big ifstatement. See the number to letter problem for this.
Development Strategy
The representation of a grid of letters as
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
