I am trying to make some error-catching code. It will always execute the else
block of the first if
statement, no matter what the function's input was. Why is it doing this?
This is the error-catching code:
def rgbtohex(r=0, g=0, b=0):
'''Converts RGB values to hecadeximal values. Supports 3 integers, one list, or one tuple.'''
if type(r) == 'int' and type(g) == 'int' and type(b) == 'int':
if r > 255 or g > 255 or b > 255:
raise ValueError('one or more arguments are above 255.')
elif type(r) == 'list' or type(r) == 'tuple':
if r[0] > 255 or r[1] > 255 or r[2] > 255:
raise ValueError('one or more index values are above 255.')
if g == 0 and b == 0:
r = r[0]
g = r[1]
b = r[2]
else:
raise TypeError('rgb values not integers, single list, or single tuple.')
return
else:
raise TypeError('one or more arguments are not integers.')
...