Conditionals and Control Flow (Codecademy Python 9/15)

Asked

Viewed 236 times

1

Hello, I’m performing an exercise of Codecademy and I have to solve the following conditions:

  • Match bool_one to False or not True and True result
  • Match bool_two to False and not True or True result
  • Match bool_three to True and not (False or False)
  • Match bool_four to the result of not True or False and not True
  • Match bool_five to False or not (True and True)

Follow my answers below:

bool_one = False
bool_two = False
bool_three = True
bool_four = True
bool_five = False

But the exercise validator is indicating that one or more answers are wrong.

  • which message appears when Voce tries to proceed?

  • Be sure to have a value for each of the 5 variables!

1 answer

4

Your mistake is in the second item, which is this:

  • Match bool_two to False and not True or True result

Running the code:

print False and not True or True

You will get as a result:

True

Looking at the precedence table in Python Docs - Expressions you will see that the not takes greater precedence among the operators of this expression, and the and has the second highest precedence, being it executed before the or but after the not. Therefore the compiler makes the following calculations:

  • not True => False
  • False and False => False
  • False or True => True (final result)

By doing a test and giving greater precedence to the or you can see that the result is False. Example:

print False and not (True or True)

Upshot:

False

  • I keep getting the same error: Be sure to have a value for each of the 5 variables!

  • And are you sure that you have associated a value for each of the 5 variables? There is more of your code that you could be showing?

  • No, that’s all.

  • 1

    @Renoirdosreis I took this course some time ago, coming back to see how I did I saw that there is nothing wrong with your code. See: http://i.stack.Imgur.com/yiEor.png Still having the bug?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.