【问题描述】
红色(red)、蓝色(blue)和黄色(yellow)被称为原色(primary color)。 当两种原色混合时,将得到次生色(secondary color)。
规则如下:
当红色与蓝色混合时,将得到紫色(purple)。
当红色与黄色混合时,将得到橙色(orange)。
当蓝色与黄色混合时,将得到绿色(green)。
编写一个程序,根据用户输入的欲混合的两种原色,输出混合得到的次生色的名称。 如果用户输入的不是三原色的名称,或者输入的两个颜色相同,则输出“error”
【输入形式】
原色1
原色2
【输出形式】
次生色 or error
【样例输入1】
red
blue
【样例输出1】
purple
【样例输入2】
red
red
【样例输出2】
error
以下是我的代码
你把c1!=list.pop(0),改成c1!=list[0],其余的5个同理
listc = ['red', 'blue', 'yellow']
def mix(c1, c2):
if c1 != c2 and c1 in listc and c2 in listc:
if c1 != listc[0] and c2 != listc[0]:
return 'green'
elif c1 != listc[1] and c2 != listc[1]:
return 'orange'
elif c1 != listc[2] and c2 != listc[2]:
return 'purple'
else:
return 'error'
c1 = input()
c2 = input()
print(mix(c1, c2))
print(mix('red', 'blue'))
print(mix('blue', 'red'))
print(mix('red', 'yellow'))
print(mix('yellow', 'red'))
print(mix('blue', 'yellow'))
print(mix('yellow', 'blue'))
print(mix('red', 'red'))
print(mix('a', 'b'))
print(mix('red', 'b'))