0

So I want a font to be red if a condition is true, but otherwise print in green font. Look at the code down below for an example.

#if Money is greater than or equal to 0, then the font color will be green. Otherwise, the font color will be red.

from colorama import Fore
Cash = int(input("Enter random number here (This is how much money a player has)"))
print("Money: ", if (Cash) >= 0: Fore.GREEN + (Cash), else: Fore.RED + (Cash))

#this does not work on python, is there a way you can fix this?
#If I input a positive number, I get a green font.
#If I input a negative number, I get a red font.
#The output only says "SyntaxError: invalid syntax"
Brent Tersol
  • 1
  • 1
  • 1
  • You can, yours doesn't work because of syntax errors. You don't use the colons in conditional expressions. But that's probably not the way you want to go here. You should do the logic before the print to determine your foreground color and then print. – Wes S. May 01 '19 at 22:26

1 Answers1

1

You just need to rearrange your statement.

Think of it as "Print this... if this is the case... otherwise print that"

print("Money: ", Fore.GREEN + str(Cash) if Cash >= 0 else Fore.RED + str(Cash))
Cohan
  • 4,384
  • 2
  • 22
  • 40