# Block Letters done with loops and functions

Hi community. I’d like to share my solution to the Python Block Letters Exercise that uses more than just `print()`. I ended up doing this because I was just revisiting the career path to tackle what was added, without really knowing what the learner was expected to know at that point. Also, I wanted to try out using a Codebyte.

# Alexander Z Lacson # Ive learned that money is everything def printrow(A_locs:list, char): row_out = [" "]*5 for index in range(len(row_out)): if index in A_locs: index row_out[index] = char concatenated_row_out = ''.join(row_out) return(concatenated_row_out) def printascii(letters:list, char_list:list): for col in range(7): for each, char in zip(range(len(letters)), char_list): print(printrow(letters[each][col], char) + " ", end="") print("") letter_A = [ [2], [1, 3], [0, 4], list(range(5)), [0, 4], [0, 4], [0, 4], ] letter_Z = [ list(range(5)), [4], [3], [2], [1], [0], list(range(5)), ] letter_L = [[0]]*6 + [list(range(5))] letters = [letter_A, letter_Z, letter_L] char_list = ["A", "Z", "L"] printascii(letters, char_list)

The output of the codebyte doesn’t match the output in the exercise. So, here’s a snip showing the proper output:

To understand the code:

• `printrow` is a function that prints out a row of a letter.
• `printascii` serves as the “main function”. It takes a list of letter coordinates and letter characters and prints them out side by side. It makes us of `printrow`.
• The position in the grid where each character will be inserted is defined for each letter.
• The ascii character of each letter, in the proper order, is defined as a list.

To add more letters, simply declare the positions of a new letter and then add the ascii character of that letter to `char_list`.

Codebyte has a flaw that prevents it from rendering more than one space character at a time so is unsuited to this type of code.

To see this project from a completely different perspective, have a gander at this…

https://replit.com/@mtf/Block-Letter-Phrase

I don’t 100% comprehend it, but if im not mistaken, beta encodes the shape of the letters.

Good understanding. The integers are interpreted as binary numbers to produce a bitmap.

How did you get the output to look nice? on replit it was squished and didnt look neat like that.
scratch that it looks like you ran the code on a local IDE.
Thank you for introducing the word bitmap

1 Like

Nope, REPL.IT. Close the file column, give the console full window width, F11 the window and Ctrl - until everything fits.

1 Like

FTR, This example was not posted to show off, but because I believed you would get it. Build upon that belief, especially in yourself. Just because I didn’t adopt your code doesn’t mean it didn’t deserve notice, and you got mine; ergo, these followings.

1 Like