In this assignment, you will debug and modify a program

randomletters.py

that should

generate a random show” of all 26 alphabet letters across a 10 * 10 matrix. (The given

skeleton code is available on D2L.)

The matrix will contain characters (all `.’ initially). Within the matrix, the program

must present all letters from `A’ to `Z’. That is, there are 26 matrix elements that will be

labeled with the letters

A

through

Z

. There are three requirements for the random letters

presented in the matrix:

1. No letter will go outside the matrix

2. Every letter from the alphabet will be presented once and only once

3. The presentation is random. That is, the output by running your program is different

from the output by running your program again.

Below is the skeleton code:

#You need to debug and modify the program so that it is able to do random walking
import random

N = 10
FILLER = ‘.’
  
#create a list to represent a row
#The row at first is filled with FILLER ‘.’
line = []
for i in range(N):
line.append(FILLER)

#create a matrix
#The matrix is the maze to walk
a=[]
for i in range(N):
line = line[:]
a.append(line)

#always starts at the left top corner of the matrix
#fill the matrix cell at the left top corner ‘A’
x = 0
y = 0
letter = ‘A’
a[x][y] = letter

#a sequence of random walk steps
#The below loop will settle the next letter
letter = chr(ord(letter) + 1)

#The following loop broken due to
#running out of letters

while (letter
#find (x,y) for the current letter
#check the interative book chapter 5.4 random module for methods to use

#update the letter to present

  

for i in range(N):
print(a[i]) #this line should be changed
#hints: use (‘ ‘.join(a[i])) to get a string
#print the ith row a[i] of the matrix

  
  



Source link

Leave a Reply

Your email address will not be published.