In this lesson, you’ll learn to make your Python programs more exciting by printing colorful and styled text on the console. Imagine being able to print messages in bright red, underline important words, or even display text that looks "dim" or faded — like a deactivated button!
We’ll explore a set of magical codes called ANSI escape codes, which allow you to control the appearance of your text in the terminal.
ANSI escape codes are special sequences that allow you to modify text style and color. You can use these to make text stand out, just like highlighting words or changing fonts in a document.
\033[<code1>;<code2>;...;<codeN>m
\033 (or \x1b) = the ESC character that starts the sequence.
[ ... m = encloses the SGR (Select Graphic Rendition) codes.
<code1>, <code2>, ... = numbers that define styles, text colors, and background colors.
Use ; to separate multiple codes.
\033[0m resets everything back to normal.
Here's an example of how to use it...
But, Let's be honest... do you really want to type that weird string EVERY TIME you want a color?? NO WAY! There has to be a BETTER WAY!!!
Strings have something cool which help us out... we can combine them using the + operator
At the top of your file, let's declare these strings
These will represent the ANSI Sequences for colors, styles, etc...
Which one do you like better?
bold_red = "\033[1;31mThis is Bold Red Text\033[0m"
or
bold_red = f"{BOLD}{RED}This is Bold Red Text{RESET}"
Once you created your strings, you can REALLY EASILY JUST USE F-STRINGS!!!
SpongeBob is writing his diary entry for “Best Day Ever #5,283,” but plain yellow text won’t cut it. He wants his words to burst with rainbow magic so every letter shines like a jellyfish parade through Goo Lagoon. 🪼✨
Get 7 Lines of input from the user, and output them a different color every line, so it looks like a rainbow.
It can be 7 Words, Phrases, etc...
Print the phrase "BEST DAY EVER" at the top of your program, with each letter being a different color!!
Here's an example of how to use it...
These change the color behind the text you're writing...
Here's an example of how to use it...
REMEMBER.. the SEMICOLON is used to separate different styles!!! That's the only reason it's there
Let's Use CONCATENATION
We're gonna leverage the AWESOME Power of the + operator to make this a BREEZE and CONCATENATE strings
Remember... There are more than these! You can look any up that you'd like, or include any that we're missing, but you should make sure that the top of your file has all of the ANSI Codes to the left!!
Most people think terminals can only do the “boring 16 colors” — red, green, blue, and their bright cousins. But modern terminals actually support 24-bit color, which means over 16 million shades, just like you’d get in Photoshop or a paint program.
\033[38;2;R;G;Bm → set the text color (foreground)
\033[48;2;R;G;Bm → set the background color
Where R, G, and B are numbers from 0 to 255 (the same way we describe digital colors everywhere else).
\033[38;2;255;0;0m = 🔴 bright red text
\033[38;2;0;255;0m = 🟢 green text
\033[48;2;255;255;0m = 🟡 yellow background
This is way cooler than the simple ANSI Colors, but here's the catch... sometimes it doesn't work if the terminal isn't MODERN! So.. Use at your own risk.
Additionally, you also need to know the RGB Value for the color you want (which is easy to find and look up!
The Starcourt-era mall just reopened its retro arcade, and they’re featuring student-made neon marquees on the big wall: glowing banners that show a player’s name, game, high score, and a catchphrase. Your job is to design a console poster that looks like it was ripped from an ‘80s cabinet or a modern e-sports overlay — all with ANSI color + style codes.
A multi-section, colorized “marquee” printed to the terminal using only:
Variables + string/numeric input
f-strings and string methods (upper(), center(), ljust(), etc.)
ANSI foreground, background, and style codes (bold, underline, dim, etc.)
You Can Have More than 6 Inputs, but don't go higher than 10, unless you have a REALLY COOL IDEA
A Symbol for the header
Player name
Favorite emoji
Game/Title
Team
Short tagline/catchphrase
High score (number)
A top neon banner line (bold color on a contrasting background)
A centered title line (game or theme) with underline or reverse video
A nameplate row (player name in bold + an emoji)
A stats block (e.g., “HIGH SCORE: 12345”, “TEAM: BLUE”, “NEON x3”) with padded alignment
A quote/catchphrase line styled differently (e.g., dim or bright color)
A bottom footer with a tiny credit or fake sponsor (new color)
Proper RESET after every styled segment so colors don’t bleed
Make your Marquee EVEN MORE COLORFUL with RGB Codes. If you successfully do this, you'll get even more points! (+25)