如果颜色无效,我正在尝试显示print()错误消息:
red = "red"
green = "green"
yellow = "yellow"
blue = "blue"
left = "left"
center = "center"
right = "right"
def move(system,pillar):
if (system == "red"):
if (pillar == "left"):
# Code to be executed.
else:
print("That is not a valid direction!")
else:
print("That is not a valid color!")
然而,当我执行此操作时,我希望它执行print(“那是无效的颜色!”),而不是声明橙色未定义。
move(orange,left)
答案 0 :(得分:0)
由于您尚未定义名为orange
的变量,因此您需要像这样调用move
:
move("orange", "left")
请注意,变量的名称及其值是两个不同的东西。这将是对move
定义的有效调用:
foo = "red"
bar = "left"
move(foo, bar)