Looking for reliable programming assignment help? At www.programminghomeworkhelp.com, we simplify complex topics for students. Here's a challenging question our expert recently solved:
Question: Write a Python function to determine if a given string is a valid hexadecimal color code (e.g., "#1a2b3c". The string must start with a "#" followed by exactly six characters (0-9, A-F).
Solution:
import re
def is_hex_color(code):
pattern = r'^#[0-9A-Fa-f]{6}$'
return bool(re.match(pattern, code))
# Example Usage
print(is_hex_color("#1a2b3c") # True
print(is_hex_color("123456") # False
Like
Comment
Share