Error on the RGB-HEX Converter project

Hello everyone I don’t understand this error on line 15. The programm is telling me that on line 15 red is not defined but, why? It is indented inside of the function it should ready red right? HELP PLEASE!!!

def rgb_hex():
invalid_msg = ‘Invalid value.’
red = int(raw_input('Enter a red value: '))
if (red < 0 or red > 225):
print invalid_msg
return

green = int(raw_input('Enter a green value: '))
if (green < 0 or green > 225):
print invalid_msg
return

blue = int(raw_input('Enter a blue value: '))
if (blue < 0 or blue > 225):
print invalid_msg
return

val = (red << 16) + (green << 8) + blue
print '%s' % (hex(val)[2:]).upper()

def hex_rgb():
hex_val = raw_input('Enter the color (six hexadecimal digits): ')
if hex_val != 6:
print ‘Invalid value.’
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 == ‘X’ or option == ‘x’:
break
else:
print ‘Error’

convert()

THANKS A LOT!!

Could you please re-post your code using the </> icon? Click the icon first, then paste your code in the space indicated. Then we will be able to see exactly how your code is indented.

Also … please post a link to the exercise.