将布尔运算符与流控制语句if、else、input和prin组合

2024-04-29 20:45:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我对编程一无所知。我开始用“automatetheboringstuff”学习python3。我读了第二章,流控制和布尔运算符。你知道吗

我试着让脚本说“那是不正确的。”当任何不是“黄色和蓝色”或“蓝色和黄色”的内容被填写时。 问题是,即使填写“poop”,也会说“这是正确的,干得好!”即使它应该说“那是不正确的”。你知道吗

我问了一个在这家公司工作的朋友,他的同事看了看,说这家公司看起来应该能用。但它没有按我预期的方式工作。为什么不?你知道吗

我希望有人能帮忙。如果我犯了一个巨大的新手错误,我会提前感谢你,并致以诚挚的歉意!你知道吗

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.')

Tags: andthatis编程公司运算符bluepython3
1条回答
网友
1楼 · 发布于 2024-04-29 20:45:14

你可能想读一下Operator Precedance。 必须创建两个单独的布尔表达式:

if colourGreen == 'b and y' or colourGreen == 'y and b':
    print('green')
else:
    print('not green')

相关问题 更多 >