Combining Boolean operators with Flow Control Statements if, else, input and print [duplicate]












0
















This question already has an answer here:




  • How to test multiple variables against a value?

    20 answers




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









share|improve this question















marked as duplicate by jpp, Lafexlos, eyllanesc python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 15:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 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 and produce a mcve mcve2

    – user32185
    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 How to Ask. :) (Most importantly, we need code as text and a Minimal, Complete, and Verifiable example.)

    – 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
















0
















This question already has an answer here:




  • How to test multiple variables against a value?

    20 answers




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









share|improve this question















marked as duplicate by jpp, Lafexlos, eyllanesc python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 15:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 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 and produce a mcve mcve2

    – user32185
    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 How to Ask. :) (Most importantly, we need code as text and a Minimal, Complete, and Verifiable example.)

    – 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














0












0








0









This question already has an answer here:




  • How to test multiple variables against a value?

    20 answers




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









share|improve this question

















This question already has an answer here:




  • How to test multiple variables against a value?

    20 answers




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




This question already has an answer here:




  • How to test multiple variables against a value?

    20 answers








python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 17:11







Tjeerd

















asked Nov 21 '18 at 14:55









TjeerdTjeerd

155




155




marked as duplicate by jpp, Lafexlos, eyllanesc python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 15:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by jpp, Lafexlos, eyllanesc python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 15:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 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 and produce a mcve mcve2

    – user32185
    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 How to Ask. :) (Most importantly, we need code as text and a Minimal, Complete, and Verifiable example.)

    – 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














  • 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 and produce a mcve mcve2

    – user32185
    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 How to Ask. :) (Most importantly, we need code as text and a Minimal, Complete, and Verifiable example.)

    – 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








2




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 and produce a mcve mcve2

– user32185
Nov 21 '18 at 14:58





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 and produce a mcve mcve2

– user32185
Nov 21 '18 at 14:58




1




1





We can probably solve your rookie programming mistake once you fix your rookie question asking mistake by reading How to Ask. :) (Most importantly, we need code as text and a Minimal, Complete, and Verifiable example.)

– timgeb
Nov 21 '18 at 14:59







We can probably solve your rookie programming mistake once you fix your rookie question asking mistake by reading How to Ask. :) (Most importantly, we need code as text and a Minimal, Complete, and Verifiable example.)

– 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





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







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




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





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 Answer
1






active

oldest

votes


















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





share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









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





    share|improve this answer






























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





      share|improve this answer




























        0












        0








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





        share|improve this answer















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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 '18 at 15:41









        rmalviya

        765219




        765219










        answered Nov 21 '18 at 15:01









        BenBen

        2,92821725




        2,92821725

















            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents