Complete the function by filling in the missing parts. The color_translator function receives the name of a color, then prints its hexadecimal value. Currently, it only supports the three additive primary colors (red, green, blue), so it returns “unknown” for all other colors.
def color_translator(color):
if color == “red”:
hex_color = “#ff0000”
elif ___ == “green”:
hex_color = “#00ff00”
elif ___ == “blue”:
hex_color = “#0000ff”
else:
hex_color = “unknown”
return ___
print(color_translator(“blue”)) # Should be #0000ff
print(color_translator(“yellow”)) # Should be
unknown
print(color_translator(“red”)) # Should be #ff0000
print(color_translator(“black”)) # Should be
unknown
print(color_translator(“green”)) # Should be #00ff00
print(color_translator("")) # Should be unknown
RunReset
Incorrect
RuntimeErrorElement(RuntimeError,Error on line 2:
if color == “red”:
^
IndentationError: expected an indented block
)
0 / 1 point
I’m afraid we’re not mind readers and cannot tell what the error is if
you don’t tell us. Can you copy and paste (don’t rewrite it from memory)
the full error message, starting with the line “Traceback”?
The Python developers have spent a lot of time trying to make the
interpreter give good, helpful error messages. They don’t always
succeed, but often if you read the error message it will tell you
exactly what you need to know to fix the problem.
Unfortunately, sometimes “invalid syntax” is the best the
interpreter can do, but even there, with a little bit of
experience you will soon be able to tell what is wrong.
P.S. don’t forget that you are supposed to fill in the ___ blanks with
code. If you just try to run it with ___ blanks, you will get an
error. You need to replace each blank with what you think goes in its
place. They are not necessarily all the same!
def color_translator(color):
if color == “red”:
hex_color = “#ff0000”
elif color == “green”:
hex_color = “#00ff00”
elif color == “blue”:
hex_color = “#0000ff”
else:
hex_color = “unknown”
return hex_color
print(color_translator(“blue”)) # Should be #0000ff
print(color_translator(“yellow”)) # Should be unknown
print(color_translator(“red”)) # Should be #ff0000
print(color_translator(“black”)) # Should be unknown
print(color_translator(“green”)) # Should be #00ff00
print(color_translator("")) # Should be unknown
I know this is a little old but… What i did was replace “hex_color =” with “return”
I was getting the same error messages but this seemed to work well.