![]() ![]() If you want to print in a row instead of a column, add a second argument to your print function to specify that you don’t want to start a new line after the colourful ‘X’. Since we have six elements in the array we run the loop six times. The loop goes through each color in the array, one at a time, first to last, and each time it runs the “print” statement with the current selected color. Double check that every open bracket has a closing bracket, and that your function arguments are properly nested. To efficiently display our colours, we’ll use a structure called a “for each” loop. The result is a bit of a strange rainbow - cyan and magenta, but no purple or yellow - so let’s see how it looks printed out. NOTE: for Python, you can use either single or double quotes for strings, as long as you open and close with the same one. The next step in our code is creating a list of all possible colours, in the order they appear in the rainbow:Ĭolors = Sadly, termcolor’s palette is pretty limited - nothing fancy like indigo or light fuchsia. Nothing to worry about! As long as your green “Hello world” text appears, your code is running fine. You may noticed a paragraph of white text appearing in the console - that’s just the website tracking its installation of the termcolor library. Try it out by pressing the green “run” button at the top of the screen. This function takes two arguments: the text you want to print, and a string describing the color of the text. Start by importing the “colored” function from Python’s “termcolor” library. ![]() On the right side is the console, where the results of the code are printed. Open up a browser and navigate to On the left hand, you’ll see your editor, where you write your code. White text on a black background isn’t very snazzy! Let’s make our output more vibrant by injecting some rainbows into the console text. Bring some colour to the console in this simple Python coding activity. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |