Complementary Colours Algorithm

Complementary colours are pairs of colours which, when combined or mixed, cancel each other out by producing a grayscale colour like white or black. When placed next to each other, they create the strongest contrast for those two colours. Complementary colours may also be called “opposite colours.”.

To find out pairs of complementary colours we can use a colour wheel. Colours which are at the opposite position on the colour wheel are complementary colours:

Complementary Colours Formula

When representing colours using the RGB colour code, we can use the following formula to work out the complementary RGB colour code:

Complementary Colours Algorithm

Our aim is to write a Python program, based on the INPUT, PROCESS and OUTPUT model in order to:

  1. INPUT: Ask the user to enter an RGB colour code
  2. PROCESS: Apply the complementary colour code formula to work out the RGB code of the complementary colour
  3. OUPUT: Display the complementary colour code on screen

Our code will be based on the following flowchart:


To complete this challenge, you will need to understand the importance of casting values from string to integer data types using the int() function and from integer to string using the str() function.

Python Code



The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 3 / 5. Vote count: 21

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: