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 120: 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 and/or short-hand syntax not yet covered in class. The restrictions include the following:
Python dictionaries
dictionary or list comprehensions, e.g.,[n *2 for i in range(10)]
with open (explicitly open and close the file instead)
the ternary operator (use an if instead)
recursion
exceptions (try/except)
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 word_grid.py.(NOTE: use an underscore, not a dash.)
Expected Behavior
First recall that a grid is a 2d-list (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 lower-case letters and, finally, print out the grid of letters one row per line.
Specifically, write a program, in a file named word_grid.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 grid_size as the first value read in.
Use the input() function (with no argument) to read in the value of seed_value as the second value read in.
Initialize the random number generator with the value seed_value.
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 grid_size and seed_value, and then intialize the random number generator:
grid_size = int(input())
seed_value = input()
random.seed(seed_value)
Return grid_size as the return value of the function.
Write a function make_grid(grid_size) that takes an integer argument grid_size and creates a grid of size grid_size \times grid_size 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 grid_size; and
the grid then consists of a list of grid_size such rows.
For example: the grid
a b c
d e f
g h i
is represented as the list of lists
[[a,b,c],[d,e,f],[g,h,i]]
Write a function print_grid(grid) 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
[[p,q,r,s],[t,u,v,w],[x,y,z,a],[b,c,d,e]]
is printed out as
p,q,r,s
t,u,v,w
x,y,z,a
b,c,d,e
Note: The indentation in this example is just to improve readability. The output from your print_grid() 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 make_grid() with the grid size as an argument; the function returns the grid created
call print_grid() using the grid returned by make_grid() as its argument; print out the grid.
Programming Requirements
When converting from a random number to a letter, do not use a big if-statement. 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!