[Tutor] Function - Python

Zulfadli Azhar zulfadli.azh at gmail.com
Fri Apr 10 05:10:34 EDT 2020


Hi Alan,

I just started to learn Python this week. I have some confusion here.
Please see below the code that I created. I supposed to come out with a
Return #0000ff but it's not.

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 "blue"

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

Please do not tell me a direct answer but I need an explanation on how to
come out with a Return #0000ff.

I have 3 more questions to ask as I have spent my whole day today to figure
get the correct code by referring from other sources.

Thank you
ZUL


More information about the Tutor mailing list