For learning (and testing) I made this simple dictionary with a small query in Python. but I allways get a NameError
and I just can't figure out what's wrong
the Code:
#!/usr/bin/env python3
def getColor(color):
Colors = {"red":"FF0000","green":"00FF00","blue":"0000FF"}
return Colors[color]
inputColor = str(input("Please input a color: "))
getColor(inputColor)
The Traceback:
Please input a color: blue
Traceback (most recent call last):
File "DictionaryTest", line 7, in <module>
inputColor = str(input("Please input a color: "))
File "<string>", line 1, in <module>
NameError: name 'blue' is not defined
the Solution
apperently there was a solution for this problem here is my working code:
#!/usr/bin/env python3
def getColor(color):
Colors = {"red":"FF0000","green":"00FF00","blue":"0000FF"}
print Colors[str(color)]
inputColor = str(raw_input("Please input a color: "))
getColor(inputColor)