Day 004 - Project 4 : Adventure Simulator

hi, that’s only for print. input is different, the syntax is input(str), you can’t pass multiple arguments.

You need to do input("Ok," + name + " where would you drive in your " + car + "?")

6 Likes

main.py - day4_100 days - Replit

Hi @jtshort73, your Repl seems to run fine. Do you need help with anything?

So I’m on Day 4 of the Python 100 days of Code. I’m learning about color - specifically, I’m learning how to highlight particular words in color. However, I’m having trouble with highlighting the phrase I want (“our final battle begins!”) in the color red and not simply the rest of the text (“shouts the evil…”

Question: How do I highlight a portion of a text rather than the rest of it?

Here is the relevant portion of my code that I have so far:

print("\033[31m", "'our final battle begins!'", "\033[31m",  "shouts the evil..."

so instead of this you need to reset it. so use "\033[0m"

3 Likes

So I reset it, replacing what I had with

\033[0m

but when I changed it back to the color I wanted, it still didn’t work - the rest of the script/text turned red instead of just the portion I wanted.

When using color codes like such, the most recent update to color will be used for ALL outputs, not just one. Let me show you an example:

print("\033[31mHello!")
print("Hi!")

# Both outputs with be RED!

To fix this, you need to reset it with "\033[0m" like @QwertyQwerty88 said.

print("\033[31mHello!") # This text is red
print("\033[0mHi!") # This text is normal
2 Likes

So I figured it out.

Use the red color code before the particular text, and after the text use a white color code. (Maybe that’s what “resetting” means).

1 Like

that works, but bob and I said to use the “reset” color code, which is \033[0m

kinda, yeah.

1 Like

Ok that works. Thank you

To change the color code of a text, just type the required color code before the text and at the end of it type the default color code. But in the case of a variable, the color codes have to be placed within double-quotes before and after the concatenated text.

print("\033[0;31m'Our final battle begins!\033[0;0m'shouts the evil" , enemy, "clearly missing the fact that", name, "has the power of" "\033[0;32m" ,superPower , "\033[0;0m""which means they'll win quite easily")