Member-only story

Color code using Python

Python Coding
Aug 25, 2024

--

pip install webcolors

Convert Hex to RGB using Python

from webcolors import hex_to_name

def color_code_to_name(color_code):
try:
color_name = hex_to_name(color_code)
return color_name
except ValueError:
return None
colorcode = input("Enter color code : ")
result_name = color_code_to_name(colorcode)
print(result_name)
red

Convert RGB to Hex using Python

from webcolors import name_to_hex

def color_name_to_code(color_name):
try:
color_code = name_to_hex(color_name)
return color_code
except ValueError:
return None
colorname = input("Enter color name : ")
result_code = color_name_to_code(colorname)
print(result_code)
#ffc0cb

--

--

Python Coding
Python Coding

Written by Python Coding

Learn python tips and tricks with code I Share your knowledge with us to help society. Python Quiz: https://www.clcoding.com/p/quiz-questions.html

No responses yet