Day 004 - Project 4 : Adventure Simulator

If you have any questions, comments or issues with this project please post them here!

Hey, on Day4 colours were added as a bonus and somehow that particular part didn‘t work out for me. On Day20, it‘s suggested we use different colours again … and I tried and failed again. Unfortunately, the usually so very helpful solutions didn‘t help because they don‘t include the colour idea. I would love to see an example of code with colours - be it as a solution to Day4 or Day20 - if that‘s possible!

Here’s my attempt at day 4: https://replit.com/@MattDESTROYER/Day-4?v=1

Thank you, MattDESTROYER, very much for sharing your version! I forked (is that the verb?!) it and had a look at the colour part … and it DID destroy me:) … you did way more than a real beginner could have done on Day4 of this 100 Day course. I‘ll put it aside for now and revisit it later when it (hopefully) looks less daunting than just now! Anyhow: Thank you! One day I‘ll surely understand what you have done to make it look so smart …

1 Like

It’s true, I’m not a beginner, but I honestly don’t know much Python so…

It’s really not that complex, I just created a helper function to make it easier for me and to make the code a little cleaner. The tutorial tells you you can do print("\033[ < colour > m"), then gives you a list of values for different colours. If you combine them, you can create this:

default = "\033[0m"
black = "\033[30m"
red = "\033[31m"
green = "\033[32m"
yellow = "\033[33m"
blue = "\033[34m"
purple = "\033[35m"
cyan = "\033[36m"
white = "\033[37m"

Basically, you print the colour you want to use, then the text you want to colour (but don’t forget to reset the colour to default if you want to stop using colours, because this will not automatically happen).

For example:

print(red + "Red", yellow + "Yellow", green + "Green", cyan + "Cyan", blue + "Blue", black + "Black", white + "White")

And here’s what that would look like:

Hope this helps :smiley:

4 Likes

Anjalene, to expand on what MattDESTROYER explained to you with his example. If you didn’t have the helper function, you would just type in something like the following if this helps.

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.

4 Likes

Thank you, UlyTheHumble. I will revisit the colours in a couple of days with your help and MattDestroyer’s. I’m sure I will manage now! Thanks again to both of you!

1 Like

Thank you so much, MattDestroyer, for all your help! I’m sure I can do it now thanks to you (and UlyTheHumble)!

2 Likes

I can’t figure out how to use colored print I learned from day 4 of 100 days of code in python IDLE

here’s the code i learned
print(“\033[32m”, ‘Hello’)

Hey @ParanormalCoder, welcome!

You can also use this method :

from termcolor import colored

print(colored("Hello","red"))

I personally like it more!

2 Likes

Thanks i’ve been trying to figure that out for a while :grinning:

code has been updated!

Do you think it will work outside the replit?

Feel like a proper storyteller with the custom storybook that I coded up :open_book:!

https://replit.com/@JackAdem/Day-004-Project-4-Adventure-Simulator?v=1

#Replit100DaysOfCode #100DaysOfCode.

1 Like

termcolor is a Python package, so as long as it is installed this will work. Replit automatically installs packages for you so outside of Replit there might be more steps involved (also note the Replit console may look slightly different to whatever console your operating system has), but it will definitely still work.

2 Likes

(This is a note mostly for me but where others can read. This is mostly just to keep me going and motivated to finish the 100 Days Of Code.)
Day 4- Today was a lot more fun I would say with the coding part of things. We had built a store sort of where you can answer and see what will go on. I can’t wait to get into some things that I haven’t done before so I can learn from the challenge. I hope to be moving into the stuff I don’t know and I think that will start happening quite soon. I think at the pace the course is going I should get into that stuff very soon.
Extra Note:
Once again, I am quite worried as tomorrow marks the start of my first weekend while being on this challenge. Like I said in my last post on Day 3:

I hope I won’t forget as I am having a lot of fun with this.