# BIT / RGB>Hex converter. Error "takes no arguments (1 given)"

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!

Hi all,
This is my first post on the forum, so I hope I am able to follow the guidelines.
I have tried a bunch of different things but I keep getting the error message “takes no arguments (1 given)”
I posted the project above. Here is my code:
` ` `
def rgb_hex():
invalid_msg = “The values entered are invalid”
red = int(raw_input("Please enter a value for red: "))
if red > 255 or red < 0:
print invalid_msg
return
green = int(raw_input("Please enter a value for green: "))
if green > 255 or green < 0:
print invalid_msg
return
blue = int(raw_input("Please enter a value for blue: "))
if blue > 255 or blue < 0:
print invalid_msg
return
val = (red << 16) + (green << 8) + blue
rgb_hex(val)
print “%s” % (hex(val)[2:]).upper()

def hex_rgb():
hex_val = raw_input("Enter a hexadecimal value: ")
if len(hex_val) != 6:
print “Please enter a six digit number”
return
else:
hex_val = int(hex_val, 16)
two_hex_digits = 2 ** 8
blue = hex_val % two_hex_digits
hex_val = hex_val >> 8
green = hex_val % two_hex_digits
hex_val = hex_val >> 8
red = hex_val % two_hex_digits
print “Red: %s Green: %s Blue: %s” % (red, green, blue)

def convert():
while True:
option = raw_input("Enter 1 to convert RGB to HEX. Enter 2 to convert HEX to RGB. Enter X to Exit: ")
if option == “1”:
print “RGB to HEX…”
rgb_hex()
elif option == “2”:
print “HEX to RGB…”
hex_rgb()
elif option == “X” or option == “x”:
break
else:
print “Error.”
convert()

` ` `

Too be honest , it is a bit difficult to read as the code is not neatly indented. Using preformatted text would improve readability significantly.

Check the line which says `rgb_hex(val)` within the rgb_hex function and see if you can figure out what is going wrong there!

I see a problem with the `rgb_hex` function here:

it has 0 parameters, but that does does not match

… when you called the function, it had 1 argument.

I’m sorry. I did add the backticks when I was writing the post so I don’t know why they aren’t there.

Thanks! I tried to do this, I don’t know why it didn’t work.

Thanks! that was it. I think I started writing this, then forgot about it while I was reading the tasks and then must have thought it was relevant code and left it…

Thank you all for the help!