I am on day 4 of the 100 days of python and I really wanted to color my variables following the video. I copied the code in the video except replaced it with what I wanted to print and this happened:
I don’t know if this will show up but basically, I wanted the input of the place variable to be yellow and this is what I wrote:
print(“it was just a normal day in\033[33]m”,Place,“\033[33]m, nothing much going on at the moment.”)
but what was printed out instead was:
it was just a normal day inm {Place} m, nothing much going on at the moment
without the place changing to yellow.
I would really appreciate is someone could help, thanks.
Instead of “\033[33]m” try “\033[0;33m”.
Also as a shortcut you can write the escape character as ‘\e’ rather than ‘\033’ for convenience.
Thirdly you can use ‘\n’ as a newline character rather than doing a empty print() . So the print statement above it could be print("Alrighty, we are all set. Let's get started\n")
Example:
print(“This is a \033[31mRed\033[0m word.”)
The above example should print the word Red in red color. The first color change using the \033[31m changes the color before the word Red to the color red and then the color change after the word Red using the \033[0m changes the color back to the default color before the last of the string ending in “word.”. Hope this helps.
hi @Claire123456789 looking at your code i can see on thing
you did
\033[33]m
i think you are supposed to do
\033[33m
so your not supposed to add closing brackets even though replit tries to make you use them
this is an example
fruit = input("""
which fruit do you like best
apple
banana
blueberry
watermelon
""")
if fruit.lower() == "apple":
colorcode = "\033[31m"
color = "red"
if fruit.lower() == "watermelon":
colorcode = "\033[32m"
color = "green"
if fruit.lower() == "banana":
colorcode = "\033[33m"
color = "yellow"
if fruit.lower() == "blueberry":
colorcode = "\033[33m"
color = "blue"
white = "\033[0m"
sentence = "so your favorite fruit is a " + colorcode + fruit + white + " Because they are the color " + colorcode + color + white + " Mine is \033[33mbananas"
print(sentence)