Question: Okay, so I have this code in python where Im supposed to make a grid of random letters based on the Nth length and width
Okay, so I have this code in python where Im supposed to make a grid of random letters based on the Nth length and width and I have to use a seed so it can have the same solution. I was able to make the code but my problem is that i have to split it up into functions and i dont know how to return the value of one function to another.
This is what i have for my code so far:
import random
def init():#this is one function where it calls out the number for its length and the seed n = int(input( ))#makes the input into an integer for the size of the grid s = input( ) random.seed(s) #def make_grid(n): this should be second function length= n abc= 'abcdefghijklmnopqrstuvwxyz' #the sring for all the random letters are comming from grid = [] #empty list to store the random words from the abc string for i in range(length): new_list = [] for j in range(length): char = random.randint(0,25) #numbers being chosen for the characters of the abc new_list.append(abc[char]) #append the letters of the acb string to the new list. grid.append(new_list) #add the new list to the grid #def print_grid(grid): this should be the third function # grid is the list created from new list for row in grid: #Printing not so random grid print(row) def main(): init() #make_grid(n) #print_grid(grid) main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
