First things first: What does ASCII mean?

ASCII stands for American Standard Code for Information Interchange. Computers encode letters, numbers, and other characters using standardized codes to save disk space. ASCII has become a universal standard for encoding characters, and creative computer geeks have taken advantage of this…to make art.

You can try painting your digital masterpiece at home. Today, we’ll be playing with ASCII text.


Time to add a couple of features to make the program work better.

  1. A while True loop in the main() function so that the program will run as many times as you want.
  2. An exception for if the user tries to print a letter or character that isn't in our font dictionary, which right now will give us a KeyError.

So let's adjust our main() function first:

def main():
 while True:
 message = getInput()
 if message == "":
 break
 convertToFont(message)

The while True would make our program run in an infinite loop. We add the extra if statement so that the user can break the infinite loop by hitting Enter instead of typing a message. Let's let them know that:

def getInput():
 text = input("What is your message? (Hit ENTER to exit) ").upper()
 return text

Now, let's take care of the issue of our user trying a character we haven't defined in our font dictionary.

def convertToFont(message):
 height = len(font["A"])
 for row in range(height):
 for letter in message:
 if letter in font:
 print(font[letter][row], end="")
 else:
 print(font["missing"][row], end="")
 print()

Of course, this requires that our dictionary have a character whose key is "missing". If you look at font1 and font2, they both have a "missing" character at the end.

If you've learned how to use try and except in a previous bonus exercise, try rewriting the conditional above as a try/except statement instead.

And, if you have lots of free time and you're really bored, you can try creating your own font! Remember to be careful about the structure of the font dictionary.