# Help

#1

Please help me with this code. Here are the instructions
This time we’ll give the expected result, and you’ll use some combination of boolean operators to achieve that result.

Remember, the boolean operators are and, or, and not. Use each one at least once!
Here is what I have so far

# Make me false!

bool_one = (2 <= 2) and “Alpha” == “Bravo” # We did this one for you!

bool_two =

# Make me false!

bool_three = (4 <= 4) and “Alpha” == “Bravo”

bool_four =

# Make me true!

bool_five =

#2
``````Make me false!

bool_one = (2 <= 2) and “Alpha” == “Bravo”
``````

Let’s look at the first example.There are two operands, and the logical operator `and`. To be True, both operands must be true. If any one of them is false, the result is False.

So, to write a False expression that uses AND, just make one of the operands False, or write the whole thing as True and then NOT the outcome.

``````True and False      =>  False
False and True      =>  False
False and False     =>  False
not(True and True)  =>  False
``````

In this exercise we have full creative license to write any expressions we wish, just so long as we use the logical operators at least once, each.

Now looking at the example, it takes the form, T and F, so we can see the result will be False. Invent any number of expressions and don’t pull any punches.

``````5 == int('5')  =>  True
42 == 6 * 7    =>  True
'a' < 'b'      =>  True
'a' and 'b'    =>  True
``````

Approach this exercise in this way and have some fun with it. Do this stuff in your head or on paper as much as possible. Create a number of expressions and then test the lot to see if you have a handle on them.

#3

can you give me an example? I really don’t understand the and “Alpha” == “Bravo”

#4

Is there a good book out there I can buy to remember all the code so far? I am almost at 20% at code academy in under three weeks. It seems that the last 3 or 4 lessons all I did was copy and paste, in which I do not get a full understanding of the code.

#5

“Alpha” is a string, as is, “Bravo”. They are not the same so the expression below (a comparison for equality) yields False.

``````"Alpha" == "Bravo"   # False
``````

The comparison operators are a big part of conditional expressions, so be sure to go back and review them with lots of practice.

``````# > greater than
6 > 2 * 3        =>  False
6 > 2 + 3        =>  True

# < less than
2 * 3 < 6        =>  False
2 + 3 < 6        =>  True

# == equal to
2 + 3 == 6       =>  False
2 * 3 == 6       =>  True
``````

String characters are ordinal, meaning the closer to the beginning of the alphabet, the lower the character code.

```````a' < 'b'        =>  True
'A' < 'B'        =>  True
'a' < 'A'        =>  False
'b' < 'B'        =>  False
``````

ASCII 97 is less than ASCII 98; ASCII 97 is not less then ASCII 65.

#6

Thanks for the info. I need to find a book for a better understanding.

#7

Look for the online editions of,

1. Learning Python the Hard Way
2. Hitchhikers Guide to Python

The first one covers Python 2, the second Python 3 with an eye to the previous version. There is a link to it in the Corner Bar from a few weeks ago.

#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.