1.11M Members

Changing output color?

 
0
 

Hey guys,

Is it possible to change the color of characters in a list if they do/dont meet certain conditions? So here's my code:

def checkWord(real, guess, remReal, remGuess, wrongSpot):
    # Format the letters so user knows whats wrong/right
    fullWord= real
            
    # Create copy list of real word
    realWord= list(fullWord)

    # Create index start point
    index= 0

    # Iterate for each letter in 'guess'
    for letter in guess:
        #print(letter)

        # Print letter with '[]' if it is in the wrong positon list 
        if letter in wrongSpot:
            print('[',letter,']',end='')
            # Convert letter in list to a '*'
            realWord[index]= '*'
            # Add to accumulator value
            index+=1
            # Debug
            #print (realWord)
            
        # If the letter is one of the remaining letters in the guess list but
        # it's not in the current word list so it is not in the real word,
        # print only the letter
        elif letter in remGuess and letter not in realWord:
            print(letter,end='')
            realWord[index]= '*'
            index+=1
            #print (realWord)

        # Print letter with '()' if letter is in the current word list
        elif letter in realWord:
            print('(',letter,')',end='')
            realWord[index]= '*'
            index+=1

I want the LIST characters to be changed to yellow if the first if condition is met, red and italic if the second elif condition is met, and green and bold if the last elif is met. Is there a way to go about doing this where the output prints into the shell?

 
0
 

It depends on your output shell. If you are using python in a terminal, you can print in colors with this module http://pypi.python.org/pypi/colorama . On the other hand, it won't work if you are using idle or another IDE with a graphical user interface (each GUI widget has its own rules to display text in colors, and idle for example has no user API to do this).

 
0
 

It depends on your output shell. If you are using python in a terminal, you can print in colors with this module http://pypi.python.org/pypi/colorama . On the other hand, it won't work if you are using idle or another IDE with a graphical user interface (each GUI widget has its own rules to display text in colors, and idle for example has no user API to do this).

Ok thanks!

Question Answered as of 2 Years Ago by Gribouillis
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: