I have tried to find a good formula in Python 3 to calculate the complementary colour of a rgb code eg. complementary of a = b. Is there any way to do this?
I don't think there is ready solution for this, but there is a colorsys module in standard library, it can help.
I think you first need to convert RGB into HSV or HSL, then "rotate" hue, and convert back to RGB, if you need. For example (I'm not sure about proper rotating):
from colorsys import rgb_to_hsv, hsv_to_rgb
def complementary(r, g, b):
"""returns RGB components of complementary color"""
hsv = rgb_to_hsv(r, g, b)
return hsv_to_rgb((hsv[0] + 0.5) % 1, hsv[1], hsv[2])