0

I'm completely new to programming. I started learning Python 3 using 'automatetheboringstuff'. I got to chapter 2, flow controls and Boolean operators.

I tried to let the script say 'That is incorrect.' when when anything other than 'yellow and blue' or 'blue and yellow' is filled in. The problem was that when even filling in 'poop', it would say 'That is correct, good job!' even though it should be saying 'That is incorrect.'.

I asked a friend of mine who works in IT and his colleague looked at it and said it looked like itshould work. But it isn't working the way I expect it to work. Why not?

I hope someone can help. Thanks in advance and my sincere apologies if I made a massive rookie mistake!

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.')
Tjeerd
  • 25
  • 5
  • 2
    Hi Tjeerd, welcome on SO. I hope you're going to find an answer for your question. It is a good idea to read something about [How to ask](https://stackoverflow.com/help/how-to-ask) and produce a [mcve](https://stackoverflow.com/help/mcve) [mcve2](http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports) – rpanai Nov 21 '18 at 14:58
  • 1
    We can probably solve your rookie programming mistake once you fix your rookie question asking mistake by reading [ask]. :) (Most importantly, we need code as *text* and a [MCVE].) – timgeb Nov 21 '18 at 14:59
  • Thank you for your feedback. I will make sure that I ask a question the right way next time! – Tjeerd Nov 21 '18 at 15:10
  • Don't wait for a next time! You can edit your current post by clicking the edit button. It's above these comments next to the 'share' text. Editing a post, even when it already has answers, will also help future readers to get a better grasp of the post. – Bram Vanroy Nov 21 '18 at 15:13
  • 1
    Thank you Bram Vanroy. I'm going to try and tidy my question up a bit now. – Tjeerd Nov 21 '18 at 15:21

1 Answers1

0

You may want to read about Operator Precedance. You have to make two separate boolean expressions:

if colourGreen == 'b and y' or colourGreen == 'y and b':
    print('green')
else:
    print('not green')
rmalviya
  • 1,847
  • 12
  • 39
Ben
  • 5,952
  • 4
  • 33
  • 44