title: Converting Hex to RGB value in Python
body: <p>Working off Jeremy's response here: <a href="https://stackoverflow.com/questions/214359/converting-hex-color-to-rgb-and-vice-versa">Converting hex color to RGB and vice-versa</a> I was able to get a python program to convert preset colour hex codes (example #B4FBB8), however from an end-user perspective we can't ask people to edit code &amp; run from there. How can one prompt the user to enter a hex value and then have it spit out a RGB value from there? </p>
  
  <p>Here's the code I have thus far:</p>
  
  <pre><code>def hex_to_rgb(value):
      value = value.lstrip('#')
      lv = len(value)
      return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
  
  
  def rgb_to_hex(rgb):
      return '#%02x%02x%02x' % rgb
  
  hex_to_rgb("#ffffff")              # ==&gt; (255, 255, 255)
  hex_to_rgb("#ffffffffffff")        # ==&gt; (65535, 65535, 65535)
  rgb_to_hex((255, 255, 255))        # ==&gt; '#ffffff'
  rgb_to_hex((65535, 65535, 65535))  # ==&gt; '#ffffffffffff'
  
  print('Please enter your colour hex')
  
  hex == input("")
  
  print('Calculating...')
  print(hex_to_rgb(hex()))
  </code></pre>
  
  <p>Using the line <code>print(hex_to_rgb('#B4FBB8'))</code> I'm able to get it to spit out the correct RGB value which is (180, 251, 184)</p>
  
  <p>It's probably super simple - I'm still pretty rough with Python. </p>