pythonpython-3.xcolorscolorama

How to do make my variable a color in python?


print("Question 1:") #Question 1
    
print("KPH \t MPH")
for KPH in range(60,131,10): #range km/h
    print(KPH,format(KPH*0.6214,"10.1f")) 

This program takes a range of speeds in km/h (60-130) and converts them to to mph. I cant figure out how to make the km/h one color and the miles/h another color. Could someone please help?


Solution

  • You could use color codes found here

    For example:

    print("Question 1:")  # Question 1
    
    RED = "\u001b[31m"
    CYAN = "\u001b[36m"
    
    print(f"{RED}KPH \t {CYAN}MPH")
    for KPH in range(60, 131, 10):  # range km/h
        print(RED + str(KPH), CYAN + format(KPH * 0.6214, "10.1f"))