我重新制作了Mastermind游戏,而且我被困在了一些"如果"声明
我正在尝试让它告诉用户,如果颜色与guess1
中的颜色不同,但正确的颜色是guess2
它会print "guess 1 right color wrong position"
Python V-2.7.8
colors = ('R','B','G','P','Y','O')
Color1 = random.choice(colors)
Color2 = random.choice(colors)
Color3 = random.choice(colors)
Color4 = random.choice(colors)
guess1 = raw_input("First Color: ")
guess2 = raw_input("Second Color: ")
guess3 = raw_input("Third Color: ")
guess4 = raw_input("Fourth Color: ")
guesses = (guess1,guess2,guess3,guess4)
Allcolors = (Color1,Color2,Color3,Color4)
if guesses == Allcolors:
print "All colors are correct!"
if guesses != Allcolors:
####
if guess1 == Color2 or Color3 or Color4:
print "Guess 1 right color wrong position"
if guess1 == Color1:
print "Color 1 is correct"
####
if guess2 == Color2:
print "Color 2 is correct"
if guess3 == Color3:
print "Color 3 is correct"
if guess4 == Color4:
print "Color 4 is correct"
答案 0 :(得分:0)
if guess1 == Color2 or Color3 or Color4:
这不起作用。你必须重复变量:
if guess1 == Color2 or guess1 == Color3 or guess1 == Color4:
您还可以使用in
运算符查看容器:
if guess1 in (Color2, Color3, Color4):