-2

I have made a program in where I have two separate players, as the players go through my game I want it to be clear what players score is by colour, so for example I want Player1 text to be red but Player2 to be blue, is there anyway of doing this since Python 3 on windows has no modules for colour

  if sum == 1:
    print("Since you rolled an odd you have lost 5 points")
    x=x+1-5

if sum == 2:
    print("Since you rolled an even you have gained 10 points")
    x=x+2+10

if sum == 3:
    print("Since you rolled an odd you have lost 5 points")
    x=x+3-5

if sum == 4:
    print("Since you rolled an even you have gained 10 points")
    x=x+4+10

if sum == 5:
    print("Since you rolled an odd you have lost 5 points")
    x=x+5-5

if sum == 6:
    print("Since you rolled an even you have gained 10 points")
    x=x+6+10

if sum == 7:
    print("Since you rolled an odd you have lost 5 points")
    x=x+7-5

if sum == 8:
    print("Since you rolled an even you have gained 10 points")
    x=x+8+10

if sum == 9:
    print("Since you rolled an odd you have lost 5 points")
    x=x+9-5

if sum == 10:
    print("Since you rolled an even you have gained 10 points")
    x=x+10+10

if sum == 11:
    print("Since you rolled an odd you have lost 5 points")
    x=x+11-5

if sum == 12:
    print("Since you rolled an even you have gained 10 points")
    x=x+12+10

I want this players output to be default blue but

 if sum == 1:
    print("Since you rolled a odd you have lost 5 points")
    y=y+1-5   

if sum == 2:
    print("Since you rolled a even you have gained 10 points")
    y=y+2-10

if sum == 3:
    print("Since you rolled a odd you have lost 5 points")
    y=y+3-5

if sum == 4:
    print("Since you rolled a even you have gained 10 points")
    y=y+4+10

if sum == 5:
    print("Since you rolled a odd you have lost 5 points")                
    y=y+5-5                                         

if sum == 6:
    print("Since you rolled a even you have gained 10 points")
    y=y+6+10

if sum == 7:
    print("Since you rolled a odd you have lost 5 points")
    y=y+7-5

if sum == 8: 
    print("Since you rolled a even you have gained 10 points")
    y=y+8+10

if sum == 9:
    print("Since you rolled a odd you have lost 5 points")
    y=y+9-5

if sum == 10:
    print("Since you rolled a even you have gained 10 points")
    y=y+10+10

if sum == 11:
    print("Since you rolled a odd you have lost 5 points")
    y=y+11-5

if sum == 12:
    print("Since you rolled a even you have gained 10 points")
    y=y+12+10

This players output to be in red or any other colour, please help?

Rampers
  • 1
  • 1
  • 1
    Can you provide some minimal example code? – Joost Döbken Oct 11 '18 at 22:04
  • Are you talking about a text-based interface (in the terminal)? Windows 10 [supports ANSI escape sequences](https://stackoverflow.com/a/38617204/1016216) like most other terminals. – L3viathan Oct 11 '18 at 22:07
  • The programming language has nothing to do with that. It depends on what is eating your output. If you're printing to a console, then most [terminals interpret ANSI codes](https://stackoverflow.com/questions/287871/print-in-terminal-with-colors) to support colors, moving the cursor around, etc. If you're using a GUI toolkit then you need to work within its APIs. – I'll Eat My Hat Oct 11 '18 at 22:10
  • What does the code you've shown here have to do with your question? what have you tried/researched? – Sayse Oct 12 '18 at 06:48
  • Since their is 2 different variables (y and x) when I run the code all of it looks like it belongs to one player even with spacing, So I wanna make one players output a different colour so it is obvious what scote belongs to who – Rampers Oct 12 '18 at 07:21

1 Answers1

0

You can use the colorama module to do this: pypi.python.org/pypi/colorama - check out their documentation and screenshots.

Here's a bit of sample code for you:

from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')

You would need to run this in the command line though, you can't really do this in the python shell

hhaefliger
  • 521
  • 3
  • 18