Python Forum
Help with conversion program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with conversion program
#1
I have errors in my code, it is for converting RGB to Hex in python.
 def color(RGB):
  if RGB > 255:
    RGB = 255
  elif RGB < 0:
    RGB = 0
    RGB = hex(RGB)[2:].upper()
  if len(RGB)<2:
    RGB = '0'+RGB
  return RGB    
 def rgb(r, g, b):
  return color(r)+color(g)+color(b)
It shows for line 7. the following is thrown:

Error:
TypeError: object of type 'int' has no len()
Does anyone have recommendations to help me fix this program?

I already tried adding str() to len(RGB)<2: with no successes.
Yoriz write Aug-19-2022, 09:01 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Help with conversion program - by uwl - Aug-19-2022, 08:36 PM
RE: Help with conversion program - by deanhystad - Aug-19-2022, 09:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb Help with Tempature Conversion Program booponion 3 1,993 Oct-16-2020, 05:59 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020