我對編程完全陌生。我開始使用“automatetheboringstuff”學(xué)習(xí) Python 3。我到了第 2 章,流程控制和布爾運算符。我試圖讓腳本說“那是不正確的”。當(dāng)填寫“黃色和藍(lán)色”或“藍(lán)色和黃色”以外的任何內(nèi)容時。問題是,即使填寫“便便”,它也會說“這是正確的,干得好!” 即使它應(yīng)該說“那是不正確的。”。我問了我一個在 IT 工作的朋友,他的同事看著它說它看起來應(yīng)該可行。但它并沒有像我期望的那樣工作。為什么不呢?我希望有人可以提供幫助。提前致謝,如果我犯了一個巨大的新手錯誤,我深表歉意!print('By combining which colours would you make the following colour?')print('Green')colourGreen = input()if colourGreen == ('blue and yellow') or ('yellow and blue'): print('That is correct, good job!')else: print('That is incorrect.')
1 回答

拉丁的傳說
TA貢獻(xiàn)1789條經(jīng)驗 獲得超8個贊
您可能想閱讀有關(guān)Operator Precedance 的信息。您必須制作兩個單獨的布爾表達(dá)式:
if colourGreen == 'b and y' or colourGreen == 'y and b':
print('green')
else:
print('not green')
添加回答
舉報
0/150
提交
取消