thatonehayk
thatonehayk

Reputation: 67

Python - Print multiple colors in one line

I'm new to programming, so keep this in mind as you read my post, as I probably made a dumb mistake that I didn't realize. Basically, I was attempting to print the word "Rainbow," except that the R is red, the a is yellow, the i is green, etc. However, the following code I used to attempt to produce this output an error.

from termcolor import cprint
cprint("R", 'red' + "a", 'yellow', "i", 'green' + "n", 'blue' + "b", 'cyan' + "o", 'magenta' + "w", 'grey')

Error:

TypeError: cprint() takes from 1 to 4 positional arguments but 9 were given

My question is how can I produce my wanted output? Thanks in advance.

Upvotes: 1

Views: 2313

Answers (1)

Jim Todd
Jim Todd

Reputation: 1588

You are probably searching for colored function in termcolor module.

from termcolor import colored
print(colored("R", 'red') ,colored( "a", 'yellow'),colored( "i", 'green' ),colored( "n", 'blue'),colored( "b", 'cyan' ),colored("o", 'magenta'),colored( "w", 'grey'))

This will print each of the letter as the color you mentioned.

Upvotes: 4

Related Questions