Reputation: 17
I'm trying to make a "Welcome message" with colors.
I'm trying to have a text like this and I would like the $
characters to be white and all the " | \ _ "
characters to be green
$$\ $$\
$$ | $$ |
$$ | $$ | $$$$$$\ $$\ $$\
$$$$$$$$ |$$ __$$\ $$ | $$ |
$$ __$$ |$$$$$$$$ |$$ | $$ |
$$ | $$ |$$ ____|$$ | $$ |
$$ | $$ |\$$$$$$$\ \$$$$$$$ |
\__| \__| \_______| \____$$ |
$$\ $$ |
\$$$$$$ |
\______/
So this is what I've got so far
import sys
class color:
GREEN = '\033[92m'
print color.GREEN + """
$$\ $$\
$$ | $$ |
$$ | $$ | $$$$$$\ $$\ $$\
$$$$$$$$ |$$ __$$\ $$ | $$ |
$$ __$$ |$$$$$$$$ |$$ | $$ |
$$ | $$ |$$ ____|$$ | $$ |
$$ | $$ |\$$$$$$$\ \$$$$$$$ |
\__| \__| \_______| \____$$ |
$$\ $$ |
\$$$$$$ |
\______/
"""
The problem is it makes everything green because of the triple quotes, I want either the dollar signs or only the other characters around it | \ / _ -
Upvotes: 0
Views: 1673
Reputation: 6855
You can use string.replace
to replace $
by \033[92m$\033[0m
class color:
GREEN = '\033[92m'
BASE = '\033[0m'
print ("""
$$\ $$\
$$ | $$ |
$$ | $$ | $$$$$$\ $$\ $$\
$$$$$$$$ |$$ __$$\ $$ | $$ |
$$ __$$ |$$$$$$$$ |$$ | $$ |
$$ | $$ |$$ ____|$$ | $$ |
$$ | $$ |\$$$$$$$\ \$$$$$$$ |
\__| \__| \_______| \____$$ |
$$\ $$ |
\$$$$$$ |
\______/
""".replace('$', color.GREEN + '$' + color.BASE))
Upvotes: 3