Question
Using python: create matrix of lowercase letters by using the Python ord and chr functions that work with the ASCII numeric codes for characters. The
Using python:
create matrix of lowercase letters by using the Python ord and chr functions that work with the ASCII numeric codes for characters. The ord function takes the letter and converts it to its ASCII numeric code. The chr function takes the ASCII numeric code and converts it back to its character.
The lowercase letters have sequential ASCII numeric codes starting with 97 and ending with 122. Converting the characters to their ASCII codes allows you to increment the characters numerically.
The first row of the matrix has a to z, which is 97 to 122. So, starting with a at column 0 of row 0, you can loop 26 times placing each of the letters in that row by adding one to the ASCII code of the previous letter, and then converting the number to its character using the chr function, before placing it in the matrix.
For each inner list, (matrix row) the code is
# Adding the row number to the ASCII code for a
# starts the row with the correct letter.
# For row=0: chr_code is 97 + 0 = 97, which is a
# For row=1: chr_code is 97 + 1 = 98, which is b
chr_code = ord(a) + row
for col in range(26):
letter = chr(chr_code)
vig_row.append(letter)
chr_code = chr_code + 1
You will have to handle the wrap back to a after placing z in the matrix and appending the inner row (list) to the outer matrix.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started